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

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 openwrt双栈NAT
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用