Page 1 of 1

Upload pade works inconsistently

Posted: Fri Apr 16, 2004 4:01 pm
by verycleanteeth
I have an upload page on my site, but sometimes people send me files and they show up as 0 byte empty files. It's inconsistent. For instance, some MP3 files will go through all right and some won't. Here is the code:
------------------------------------------------------------------------------------

<?php
$userfile = $HTTP_POST_FILES['userfile']['tmp_name'];
$userfile_name = $HTTP_POST_FILES['userfile']['name'];
$userfile_size = $HTTP_POST_FILES['userfile']['size'];
$userfile_type = $HTTP_POST_FILES['userfile']['type'];
$userfile_error = $HTTP_POST_FILES['userfile']['error'];

if ($userfile_error > 0)
{
echo 'Problem, Yo: ';
switch ($userfile_error)
{
case 1: echo 'File exceeded upload_max_filesize'; break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}
$upfile = 'uploaded/'.$userfile_name;

if (is_uploaded_file($userfile))
{
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
}
}
else
{
echo 'Problem: Possible file upload attack. Filename: '.$userfile_name;
exit;
}
echo 'file uploaded successfully<br /><br />';

$fp = fopen($upfile, 'r');
$contents = fread ($fp, filesize ($upfile));
fclose ($fp);

$fp = fopen($upfile, 'w');
fwrite($fp, $contents);
fclose($fp);



?>

-------------------------------------------------------------------------------------

Am I doing something incorrectly?
Thankses.

Posted: Fri Apr 16, 2004 5:16 pm
by magicrobotmonkey
You need to find a pattern in the ones that work and the ones that dont - I would focus on the file names - look for spaces or funny characters?