duandou8457 2015-08-30 20:48
浏览 51
已采纳

PHP文件上传在服务器上失败

I am developing a website that includes functions with file upload. This was working perfectly on localhost, but once I uploaded the site to my server it fails.

I have the following code to handle the file upload:

case "upload_to_gallery":

        /*******************************
         ****   UPLOAD TO GALLERY   ****
         *******************************/

        if ($con->checkLogin() && isset($_FILES['uploaded_files'])) {
            $gallery_name = $_POST['gallery_name'];

            for ($i = 0; $i < count($_FILES['uploaded_files']['name']); $i++) {
                list($width, $height, $type, $attr) = getimagesize($_FILES["uploaded_files"]['tmp_name'][$i]);

                if ($_FILES['uploaded_files']['type'][$i] == "image/png"
                    || $_FILES['uploaded_files']['type'][$i] == "image/jpeg"
                    || $_FILES['uploaded_files']['type'][$i] == "image/gif"
                ) {
                    $imgPath = "../files/img/galleries/" . $gallery_name . "/" . $_FILES['uploaded_files']['name'][$i];
                    $thumbPath = "../files/img/galleries/" . $gallery_name . "/thumbs/" . $_FILES['uploaded_files']['name'][$i];

                    move_uploaded_file($_FILES['uploaded_files']['tmp_name'][$i], strtolower($imgPath));

                    $filehandler->makeThumbnails($imgPath, $thumbPath, 300, 215);
                }

            }
            header('location: '.MAINPATH.'/galleri/'.$gallery_name.'?billeder_uploadet');

And the errors i am getting, when trying to upload some files (images) on the server is:

Warning: move_uploaded_file(../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phptu17Hf' to '../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg' in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35

Warning: getimagesize(../files/img/galleries/Test/1383204_10200900060289437_410542691_n.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 158

Warning: Division by zero in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 159

Warning: Division by zero in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 159

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 162

When I try to upload 0 files to the server it gives me this error:

Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 26

Which I don't think makes sense, as I am checking if any files has been sent through..

I thought it might have something to do with permissions on the server, but all the relevant folders is set to '755'.

I hope someone might know what the problem could be. Any help will be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • douou1872 2015-08-31 08:35
    关注

    Check carefully your errors.

    Warning: move_uploaded_file(../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phptu17Hf' to '../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg' in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35

    Warning: getimagesize(../files/img/galleries/Test/1383204_10200900060289437_410542691_n.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 158

    You have both test and Test in your paths.

    Remember that Linux is case-sensitive for file and folder names. Windows is not. That might explain why it worked on your dev environment and why it didn't anymore on your prod server.

    So pick either one of them and stick with it (I wouldn't recommend to use uppercase characters in your paths though).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改