RE: [PHP] Uploaded CSV -> database

From: Date: Mon, 17 Oct 2005 15:43:38 +0000
Subject: RE: [PHP] Uploaded CSV -> database
Groups: php.general 
Request: Send a blank email to php-general+get-224239@lists.php.net to get a copy of this message
[snip] It looks like all of those tips will easily cover me for the latter half of the operation. Any tips on how to get the uploaded CSV file into memory in order to attack it with fgetcsv()? I'd rather not ever have to actually write the file to the server's disk. [/snip] Once you have performed move_uploaded_file() you will have to fopen and loop through the file to read and perform error checking. After you have processed the file you could then unlink() it, removing it from the server's disk. Here is an example where Excel files are uploaded as tab delimited text; /*real file name*/ $fileName = ($HTTP_POST_FILES['docfile']['name']); $docWork = "/path/to/file/after/move/"; move_uploaded_file($HTTP_POST_FILES['docfile']['tmp_name'], $docWork . $fileName) or die("File cannot be uploaded"); /* ** open uploaded file and do stuff to it */ $i = 0; $fileTab = fopen($docWork.$fileName, "r"); while(!feof($fileTab)){ $fileLine = fgets($fileTab, 1024); $arrLine = explode("\t", $fileLine); $cmLength = strlen($arrLine[0]); /* do other stuff here */ } fclose($fileTab);

« previous php.general (#224239) next »