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).

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

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作