Bug #70426 [Opn->Nab]: fGetCsv() doesn't work with php://temp or php://memory
| From: | requinix@php.net | Date: | Fri, 04 Sep 2015 09:47:35 +0000 |
| Subject: | Bug #70426 [Opn->Nab]: fGetCsv() doesn't work with php://temp or php://memory | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-195755@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70426&edit=1
ID: 70426
Updated by: requinix@php.net
Reported by: pet dot draexler at gmail dot com
Summary: fGetCsv() doesn't work with php://temp or
php://memory
-Status: Open
+Status: Not a bug
Type: Bug
Package: Filesystem function related
Operating System: Windows 10
PHP Version: 5.5.8
Block user comment: N
Private report: N
New Comment:
Opening php://temp will get you a different stream each time. If you want to use a temporary stream
like this, open it for reading and writing, copy the contents of the stream you want into it,
rewind, and begin reading.
Note that to read CSV data you don't need a temporary stream in the first place.
Previous Comments:
------------------------------------------------------------------------
[2015-09-04 09:34:53] pet dot draexler at gmail dot com
Code to test:
<?php
// To test this, you can use CSV file in this zip:
// http://spatialkeydocs.s3.amazonaws.com/FL_insurance_sample.csv.zip
$csv_file_content = file_get_contents("sample_file.csv");
$temp_file_name = "php://temp"; // when replaced with actual file name, everything works
file_put_contents($temp_file_name, $csv_file_content);
$handle = fopen($temp_file_name, "r");
$line = fGetCsv($handle, 1000, ",");
var_dump($line); // in PHP 5.5.8 returns echos bool(false)
?>
------------------------------------------------------------------------
[2015-09-04 09:22:54] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
------------------------------------------------------------------------
[2015-09-04 09:22:14] pet dot draexler at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.fgetcsv
---
I received a CSV file through POST. When I wrote it into memory and tried to read it with fGetCsv,
it'd return FALSE. As soon as I changed php://temp to actual file name, everything is working.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70426&edit=1