Posted by Jay Blanchard on 10/20/18 11:29
[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);
[Back to original message]
|