|
Posted by Jψrn Dahl-Stamnes on 02/26/07 10:33
JΓΈrn Dahl-Stamnes wrote:
> Hello folks,
>
> I need some help/advice FAST.
Here are parts of the upload script that handles the file. If you find any
errors, please let me know.
It seems like it works OK for smaller files (~70 Kb), but not for larger
files (~112 Kb). I have checked that the amount of memory my PHP script can
use is suffisient.
<?php
static $Upload_Errmsgs = array (
1 => "The uploaded file exceeds the upload_max_filesize directive in
php.ini.",
2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was
specified in the HTML form.",
3 => "The uploaded file was only partially uploaded.",
4 => "No file was uploaded."
);
if (0 != $_FILES['upfile']['error']) return "Error code:
{$Upload_Errmsgs[$_FILES['upfile']['error']]}.";
$max_size = 8* 1024 * 1024; // 8 Mb max size.
if ($max_size < $_FILES['upfile']['size'] || 0 == $_FILES['upfile'
['size']) return "Too big!";
$uploadfile = tempnam ("/tmp","att");
if (move_the_file($uploadfile))
{
$fsize = filesize ($uploadfile);
$bfh = @fopen ($uploadfile,"rb");
if ($bfh)
{
$att_data = @fread ($bfh,$fsize);
@fclose ($bfh);
$att_data = addslashes ($att_data);
} else
return "Error: Could not open uploaded file.";
$query = "INSERT INTO attachments (filetype,filedata) VALUE
('{$_FILES['upfile']['type']}','$att_data')";
mysql_query ($query,$dbh);
unlink ($uploadfile);
}
function move_the_file ($uploadfile)
{
$ok_status = false;
if (is_uploaded_file($_FILES['upfile']['tmp_name']))
{
$ok_status = @move_uploaded_file ($_FILES['upfile']['tmp_name']
$uploadfile);
}
return $ok_status;
}
?>
--
JΓΈrn Dahl-Stamnes
http://www.dahl-stamnes.net/dahls/
[Back to original message]
|