|
Posted by Rik on 10/18/06 03:19
gooofy60@gmail.com wrote:
> I need to ask anyways...
> Any chance you can FTP the CSV to the web server, along with a custom
> php script?
>
> Otherwise, you won't get far with a 5 minute restriction.
> Chop the CSV down until you can avoid the timeout, then keep adding
> more rows in chunks.
If not the uploading, but the handling is the problem:
Pseudo-code, depends a little on browser time-outs:
$start = time();
/* some code for connecting to mysql */
if(isset($_FILES)){
move_uploaded_file(//etc...);
}
$handle = fopen('/path/to/file.csv');
if(isset($_GET['start']) $check = fseek($handle,$_GET['start']);
if($check==-1){
echo 'error';
exit();
}
while(($array = fgetcsv($handle)) !== false){
//code for inserting into db
array_walk($array,'mysql_real_escape_string');
mysql_query("INSERT INTO tbl_name
(field1,field2,field3....etc)
VALUES
('".implode("','",$array)."')");
if(mysql_error()){
echo mysql_error();
break;
}
//activate timeout
if((time() - $start) > 120){ //120 seconds, to avoid time-outs
header('Location:
http://www.example.com/your_script.php?start='.rawurlencode(ftell($handle)));
exit();
}
}
echo 'Finished';
Not a very nice solution, but semi-workable when in need.
Grtz,
--
Rik Wasmus
[Back to original message]
|