move_uploaded_file() error

Posted by James R. on Stack Overflow See other posts from Stack Overflow or by James R.
Published on 2010-04-10T01:56:02Z Indexed on 2010/04/10 2:03 UTC
Read the original article Hit count: 495

Filed under:

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?

© Stack Overflow or respective owner

Related posts about php