You are here: RE: [PHP] Uploaded CSV -> database « PHP « IT news, forums, messages
RE: [PHP] Uploaded CSV -> database

Posted by Jay Blanchard on 10/09/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);

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация