Forum Moderators: coopster

Message Too Old, No Replies

Uploading file on chunks

         

Constantinff

4:32 pm on Aug 24, 2009 (gmt 0)

10+ Year Member



Here is what i have done till now
This script upload binary data to mysql database by chunks, but dont work with big files

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
fclose($fp);

$start = 0;
$chunk = 1310720;

while ($start < strlen($content)) {

$query = "INSERT INTO $dbtable (data_blob) ".
"VALUES ('substr($content,$start,$end)')";
mysql_query($query) or die('Error, query failed');
echo "File $fileName uploaded chunk starting from $start to $end<br>";
$start = $start + $chunk;
$end = $start + $chunk;
}
I think i have to read the file by parts too, but dont find such a function, any suggestion?
Thanks

Constantinff

4:53 pm on Aug 24, 2009 (gmt 0)

10+ Year Member



One more variation , think it will works better
but the gives gives error
$fp = fopen($tmpName, 'r');

$fp = fopen($tmpName, 'r') or die('Can’t open');
while (!feof($fp)) {
$chunk = fread($fp, 1310720);

$query = "INSERT INTO $dbtable (data_blob) ".
"VALUES ('$chunk')";
mysql_query($query) or die('Error, query failed');
}