php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70426 fGetCsv() doesn't work with php://temp or php://memory
Submitted: 2015-09-04 09:22 UTC Modified: 2015-09-04 09:47 UTC
From: pet dot draexler at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.5.8 OS: Windows 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pet dot draexler at gmail dot com
New email:
PHP Version: OS:

 

 [2015-09-04 09:22 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-04 09:22 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2015-09-04 09:22 UTC] 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:34 UTC] pet dot draexler at gmail dot com
-Status: Feedback +Status: Open -PHP Version: 5.5.28 +PHP Version: 5.5.8
 [2015-09-04 09:34 UTC] 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:47 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-09-04 09:47 UTC] requinix@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 16:01:27 2024 UTC