简体   繁体   English

move_uploaded_file() 错误

[英]move_uploaded_file() error

I have a website on free hosting - 000webhost.com and it allows you to upload images.我有一个免费托管网站 - 000webhost.com,它允许您上传图片。

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警告:move_uploaded_file(images/SmallSmileyFace.jpg) [function.move-uploaded-file]:无法打开流:第 76 行的 /home/a6621074/public_html/m/write.php 中的权限被拒绝

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警告:move_uploaded_file() [function.move-uploaded-file]:无法将 '/tmp/phpcmW3mo' 移动到 /home/a6621074/public_html/m/write.php 中的 'images/SmallSmileyFace.jpg' 第 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. Check your "images" folder permissions, make it 0777 (writable for everyone), for example.例如,检查您的“图像”文件夹权限,将其设置为 0777(所有人均可写)。
  2. Change "images/" path to absolute server path.将“images/”路径更改为绝对服务器路径。

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.您可能需要与您的托管服务提供商联系或尝试上传到其他文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM