tags:

views:

98

answers:

2

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?

+1  A: 

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.

Levi Hackwith
+1  A: 
  1. Check your "images" folder permissions, make it 0777 (writable for everyone), for example.
  2. Change "images/" path to absolute server path.
Sergei
How do I set it to 0777? The images folder was something that I uploaded to the hosting as well. I'm not sure how to change images/ to absolute server path? Sorry if this sounds dumb, I'm really new at this.
James R.
your ftp program should have a function somewhere that allows you to set the permissions to 0777
bumperbox
thank you, that worked.
James R.
1 FileZilla is a good free FTP client.2 Your absolute path probably is /home/a6621074/public_html/images/
Sergei