Uploading large file into database
Posted: Tue Sep 13, 2011 3:22 pm
I have a script that is trying to read in a large csv file (7MB) and insert the data into my database (MySQL). I use the same script for smaller files and it works so I'm thinking it is one of my php variables not set high enough to read in the data. Here is my php5.ini file
Here is my script file.
Here is my phpinfo.php settings for this site and hosting company (GoDaddy)
http://www.datacaresol.com/phpinfo.php
Thanks for any suggestions with this problem.
Marnie
Code: Select all
register_globals = on
allow_url_fopen = off
expose_php = Off
max_input_time = 2400
max_execution_time = 2400
upload_max_filesize = 192M
memory_limit = 256M
variables_order = "EGPCS"
extension_dir = ./
upload_tmp_dir = /tmp
precision = 12
SMTP = relay-hosting.secureserver.net
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset="Code: Select all
$lineseparator = "\n";
$fieldseparator = ",";
$csvfile = "upload/products_1.csv";
if (!file_exists($csvfile))
{
echo "file not found. Make sure the products_1.csv file is in the upload folder.\n";
exit;
}
$file = fopen($csvfile,"r");
if (!file)
{ echo "error opening data file. \n";
exit;
}
$size = filesize($csvfile);
if (!size) {
echo "file is empty.\n";
exit;
}
$csvcontent = fread($file,$size);
fclose($file);
$lines = 0;
$queries= "";
$linearray = array();
foreach(split($lineseparator,$csvcontent) as $line)
{
$lines++;
$line = trim($line,"\t");
$line = str_replace("\r","", $line);
$linearray = explode($fieldseparator,$line);
$linemysql = implode("','", $linearray);
$query = "insert into prevc_products values ('$linemysql');";
$queries .= $query . "\n";
@mysql_query($query);
http://www.datacaresol.com/phpinfo.php
Thanks for any suggestions with this problem.
Marnie