Reputation: 23
I have a website on free hosting - 000webhost.com and it allows you to upload images.
However, when I try to upload an image, I get these errors:
Warning: move_uploaded_file(images/SmallSmileyFace.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/a6621074/public_html/m/write.php on line 76
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpcmW3mo' to 'images/SmallSmileyFace.jpg' in /home/a6621074/public_html/m/write.php on line 76
This is the code:
if (!empty($_FILES['fileImage']['name'])) {
// check image type and size
if ((($imagetype == 'image/gif') || ($imagetype == 'image/jpeg') || ($imagetype == 'image/pjpeg') || ($imagetype == 'image/png'))
&& ($imagesize > 0) && ($imagesize <= 32768)) {
if ($_FILES['fileImage']['error'] == 0) {
//move file
$target = 'images/' . $image;
if (move_uploaded_file($_FILES['fileImage']['tmp_name'], $target)) {
$query = "INSERT INTO reviews (post_date, food_name, location, cafeteria, review, image, rating, user_id)
VALUES (NOW(), '$foodname', '$location', '$cafeteria', '$review', '$image', $rate, $id)";
mysqli_query($dbc, $query);
//confirm success
echo '<p>Thank you for your submission!</p>';
}
else {
echo '<p class="errmsg">There was a problem uploading your image.</p>';
}
}
@unlink($_FILES['fileImage']['tmp_name']);
}
else {
echo '<p class="errmsg">The screen shot must be a GIF, JPEG, or PNG image file no greater than 32KB in size.</p>';
}
}
Any ideas?
Upvotes: 2
Views: 6654
Reputation: 2757
Upvotes: 6
Reputation: 9332
Permission denied is usually caused by file permissions with your host. Basically, you don't have write permissions to the folder you're trying to move the file to. You might need to talk to your hosting provider or try uploading to a different folder.
Upvotes: 1