PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
hi there.....
I need help in uploading an array of files
there is some problem in the code that i am using can any one help me to over come the problem
if ($HTTP_POST_VARS['submit'])
{
if (!is_uploaded_file($HTTP_POST_FILES['file'][temp]))
{
$error = "You did not upload a file!";
unlink($HTTP_POST_FILES['file'][temp]);
// assign error message, remove uploaded file, redisplay form.
}
else
{
//A file was uploaded
$maxfilesize=30000;
if ($HTTP_POST_FILES['file']['size'] > $maxfilesize)
{
$error = "File is too large.";
unlink($HTTP_POST_FILES['file'][temp]);
// assign error message, remove uploaded file, redisplay form.
}
else
{
//File has passed all validation, copy it to the final destination and remove the temporary file:
copy($HTTP_POST_FILES['file'][temp],$HTTP_POST_FILES['file'][use]);
move_uploaded_file(['file'][use], "/place/file.new");
{
unlink($HTTP_POST_FILES['file']);
print "File has been successfully uploaded!";
exit();
}
}
}
http://www.php.net/manual/en/features.file-upload.php wrote:Note: In PHP versions prior 4.1.0 this was named $HTTP_POST_FILES and it's not an autoglobal variable like $_FILES is. PHP 3 does not support $HTTP_POST_FILES.
so, if you're doing this within a function you have to import $HTTP_POST_FILES before using it
if ($HTTP_POST_VARS['submit'])
{
if (!is_uploaded_file($HTTP_POST_FILES['file'][temp]))
{
$error = "You did not upload a file!";
unlink($HTTP_POST_FILES['file'][temp]); // <- please read
// assign error message, remove uploaded file, redisplay form.
}
else
{
//A file was uploaded
$maxfilesize=30000;
if ($HTTP_POST_FILES['file']['size'] > $maxfilesize)
{
$error = "File is too large.";
unlink($HTTP_POST_FILES['file'][temp]);
// assign error message, remove uploaded file, redisplay form.
}
else
{
//File has passed all validation, copy it to the final destination and remove the temporary file:
copy($HTTP_POST_FILES['file'][temp],$HTTP_POST_FILES['file'][use]);
move_uploaded_file(['file'][use], "/place/file.new");
{
unlink($HTTP_POST_FILES['file']);
print "File has been successfully uploaded!";
exit();
}
}
}
as you can see there's a mismatch of { and }s. Might be you only forgot to paste it here but you'd check that
so you copy the file at pointer $HTTP_POST_FILES['file']['temp'] to the location defined by pointer $HTTP_POST_FILES['file']['use'] (neither of which exist in the standard upload processing done by php) - thus overwriting whatever is there.
then you move the file again (or try to as ['file']['use'] is not a valid pointer without a global array definition) to /place/file.new from root.
maybe you should show us the code that creates the user variables ['temp'] and ['use'] in the http_post_files array - then we would at least maybe understand what they are trying to accomplish.
I'd suggest it better to just
unlink($HTTP_POST_FILES['file']['use']);
rather than overwrite it - then just move whatever is referenced by ['file']['use'] (with no array definition - must be some serious code to get that to do anything, maybe a pre-parser variable templating engine I guess) to the near root folder you defined.