splfileobject

SplFileObject + LimitIterator + offset

女生的网名这么多〃 提交于 2021-02-08 15:34:02
问题 I have data file with two lines (two lines just for my example, in real, that file can contain millions of lines) and I use SplFileObject and LimitIterator with offseting. But this combination have strange behaviour in some cases: $offset = 0; $file = new \SplFileObject($filePath); $fileIterator = new \LimitIterator($file, $offset, 100); foreach ($fileIterator as $key => $line) { echo $key; } Output is: 01 But with $offset set to 1 , output is blank (foreach doesn't iterate any line). My data

SplFileObject + LimitIterator + offset

半腔热情 提交于 2021-02-08 15:31:26
问题 I have data file with two lines (two lines just for my example, in real, that file can contain millions of lines) and I use SplFileObject and LimitIterator with offseting. But this combination have strange behaviour in some cases: $offset = 0; $file = new \SplFileObject($filePath); $fileIterator = new \LimitIterator($file, $offset, 100); foreach ($fileIterator as $key => $line) { echo $key; } Output is: 01 But with $offset set to 1 , output is blank (foreach doesn't iterate any line). My data

$file->eof() always returning false when using PHP's SplFileObject in 'r' mode

混江龙づ霸主 提交于 2019-12-23 05:12:20
问题 Why is my PHP script hanging? $path = tempnam(sys_get_temp_dir(), '').'.txt'; $fileInfo = new \SplFileInfo($path); $fileObject = $fileInfo->openFile('a'); $fileObject->fwrite("test line\n"); $fileObject2 = $fileInfo->openFile('r'); var_dump(file_exists($path)); // bool(true) var_dump(file_get_contents($path)); // string(10) "test line // " var_dump(iterator_count($fileObject2)); // Hangs on this If I delete the last line ( iterator_count(... ) and replace it with this: $i = 0; $fileObject2-

PHP LimitIterator fails (“Does not support seeking” + “Cannot rewind file”)

血红的双手。 提交于 2019-12-23 03:12:57
问题 I use SplFileObject and LimitIterator to read content from position x till y of a big file. This works perfectly when using a file path like /home/devel/stuff/myfile.log . When using a path like http://mydomain.com:8090/devel/stuff/myfile.log it does not work. The path is correct however. Does this fail when using absolute paths? The error messages are: PHP Warning: SplFileObject::rewind() [<a href='splfileobject.rewind'>splfileobject.rewind</a>]: stream does not support seeking in ... PHP

Unlink and SplFileObject

て烟熏妆下的殇ゞ 提交于 2019-12-13 13:03:41
问题 Is it possible to unlink a file from an SplFileObject? I don't see a method to close the underlying resource, and the file handle is private so one can't extend SplFileObject with that goal in mind. Are there any workarounds? 回答1: I would not recommend this, because PHP closes the file behind scenes for you. If you take a look at the php src, ext/spl/spl_directory.c : retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free

tab-delimited string to XML with PHP

六月ゝ 毕业季﹏ 提交于 2019-12-12 04:27:21
问题 I'm trying to write the tab-delimited content of a variable to XML like this: $tsvData = str_getcsv($input, "\t"); foreach($tsvData as $line => $row) { if($line > 0) { $xmlWriter->writeElement('NAME', $row[0]); $xmlWriter->writeElement('CAKE', $row[1]); $xmlWriter->writeElement('BODYPART', $row[2]); } } But it's only writing one character per XML tag instead of everything between each tab. When I use SplFileObject, geting the same tsv data but from a file, it works. What am I doing wrong with

RuntimeException SplFileInfo::getSize(): stat failed for… Laravel 4 upload image

[亡魂溺海] 提交于 2019-11-27 07:55:32
问题 I work with laravel 4 (last update) , I create a form where we could upload an image (logo/avatar). I am on MAC OS, I use sublime Text 3 , laravel and MAMP Applications . All my configuration is setting right, no running problems. My probleme is that I have this error when I submit the reaching fields from my form: RuntimeException SplFileInfo::getSize(): stat failed for /Applications/MAMP/tmp/php/phpRUJfMX Here's the code from my form nameOfTheForm.blade.php : @extends('layout.default')