File upload
Posted: Tue Mar 17, 2009 11:07 am
I am having a problem with some file upload code. The code works fine from my local system but when I upload it to my host I get errors. Below is the code (the upload code is bolded) followed by the errors - with the redirect commented out. I think I may have a permission problem from my host but I want to make sure I can't solve this with code before I check with them. If anyone can help I would appreciate it.
Error:
Upload: back.jpg
Type: image/pjpeg
Size: 8.55859375 Kb
Stored in: /tmp/phpmreoqCUpload: back.jpg
Type: image/pjpeg
Size: 8.55859375 Kb
Stored in: /tmp/phpmreoqCUpload: back.jpg
Type: image/pjpeg
Size: 8.55859375 Kb
Temp file: /tmp/phpmreoqC
Warning: move_uploaded_file(../images/back.jpg): failed to open stream: Permission denied in /home/lfchur5/public_html/staff/uploadimage.php on line 94
Warning: move_uploaded_file(): Unable to move '/tmp/phpmreoqC' to '../images/back.jpg' in /home/lfchur5/public_html/staff/uploadimage.php on line 94
Stored in: ../images/back.jpg
Code: Select all
... else{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("../images/" . $_FILES["file"]["name"])){
$error_msg = "The file already exists.";
header('LOCATION: uploadimage.php?err=' . $error_msg . '&action=create');
exit;
}else{
[b]move_uploaded_file($_FILES["file"]["tmp_name"], "../images/" . $_FILES["file"]["name"]);
echo "Stored in: " . "../images/" . $_FILES["file"]["name"];[/b]
//$error_msg = "Thank you. The file was uploaded. Upload another?";
//header('LOCATION: uploadimage.php?err=' . $error_msg . '&action=create');
//exit;
}
}
}else
{
$error_msg = "This is an invalid file. Please choose another one";
header('LOCATION: uploadimage.php?err=' . $error_msg . '&action=create');
exit;
}
Error:
Upload: back.jpg
Type: image/pjpeg
Size: 8.55859375 Kb
Stored in: /tmp/phpmreoqCUpload: back.jpg
Type: image/pjpeg
Size: 8.55859375 Kb
Stored in: /tmp/phpmreoqCUpload: back.jpg
Type: image/pjpeg
Size: 8.55859375 Kb
Temp file: /tmp/phpmreoqC
Warning: move_uploaded_file(../images/back.jpg): failed to open stream: Permission denied in /home/lfchur5/public_html/staff/uploadimage.php on line 94
Warning: move_uploaded_file(): Unable to move '/tmp/phpmreoqC' to '../images/back.jpg' in /home/lfchur5/public_html/staff/uploadimage.php on line 94
Stored in: ../images/back.jpg