I'm trying to implement therebechips's method (http://www.php.net/manual/en/features.file-upload.php) for uploading large files and storing them into a database after breaking them into smaller "chunks". I'd like to be able to do this to get around the PHP4 24MB memory limitation on processing scripts. But I'm running into problems, even on the level of understanding how his script works. Can anyone point me toward an example of a script that does this?
Or, help me parse through therebechips's script:
<?php
// Max packet size
define("MAX_SQL",50000);
$filehandle = fopen($tmp, "rb") or die( "Can't open file!" );
$query= "INSERT INTO files (name, type, size) VALUES(".
$DB->quote($name).", ".
$DB->quote($type).", ".
$DB->quote($size).
")";
// Execute Query
$result = $DB->query($query);
$file_id = mysql_insert_id();
// Copy the binary file data to the filedata table in sequential rows each containing MAX_SQL bytes
// Your table should have an index set to auto_increment
// Store the file_id to identify the data fragments
while (!feof ($filehandle)) {
$data = base64_encode(fread($filehandle,MAX_SQL));
$query = "INSERT INTO filedata (file_id, data) VALUES($file_id,\"".$data."\")";
$result = $DB->query($query);
}
fclose ($filehandle);
?>
Where is it getting the value for $tmp variable? From the $_FILES global?
How does the syntax of the query string work? I'm not sure how the $DB->quote() bits work. If I add the following lines to read data out of the $_FILES variable:
$name = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$size = $_FILES['userfile']['size'];
$type = $_FILES['userfile']['type'];
I get the following error: Fatal error: Call to a member function on a non-object in /var/www/livesite/fileshare/file_process_alt.php on line 34. This points to the first $dB->quote() lines in the query string.