【问题标题】:PHP's file upload is failing on serverPHP文件上传在服务器上失败
【发布时间】:2015-11-24 21:11:48
【问题描述】:

我正在开发一个包含文件上传功能的网站。这在本地主机上运行良好,但是一旦我将站点上传到我的服务器,它就会失败。

我有以下代码来处理文件上传:

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');

当我尝试在服务器上上传一些文件(图像)时,我遇到的错误是:

警告:move_uploaded_file(../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg) [function.move-uploaded-file]:无法打开流:/var/www/xn-中没有这样的文件或目录-cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php 在第 35 行

警告:move_uploaded_file() [function.move-uploaded-file]:无法将 '/tmp/phptu17Hf' 移动到 /var/www/ 中的 '../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg' xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php 在第 35 行

警告:getimagesize(../files/img/galleries/Test/1383204_10200900060289437_410542691_n.jpg) [function.getimagesize]:无法打开流:/var/www/xn--cstanlg-rxa 中没有这样的文件或目录.dk/public_html/lib/class/FileHandler.php 在第 158 行

警告:第 159 行 /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php 中除以零

警告:第 159 行 /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php 中除以零

警告:imagecreatetruecolor() [function.imagecreatetruecolor]:第 162 行 /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php 中的图像尺寸无效

当我尝试将 0 个文件上传到服务器时,它给了我这个错误:

警告:getimagesize() [function.getimagesize]:第 26 行 /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php 中的文件名不能为空

我认为这没有意义,因为我正在检查是否有任何文件已发送通过..

我认为这可能与服务器上的权限有关,但所有相关文件夹都设置为“755”。

我希望有人可能知道问题可能是什么。 任何帮助将不胜感激。

【问题讨论】:

  • 如果你的路径有testTest(在前3个警告中)。选择一个并坚持下去。 Linux 对路径和文件夹/文件名区分大小写。 Windows 不是。
  • $_FILES['uploaded_files'] 存在并不意味着没有任何错误。检查错误。
  • 感谢@D4V1D!就是这样。如果您发布答案,我会接受。还有@Charlotte Dunois,也谢谢。我将尝试检查错误。我刚刚读到它可以像我在我的问题中那样做,但显然情况并非如此:)

标签: php file-upload


【解决方案1】:

仔细检查你的错误。

警告:move_uploaded_file(../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg) [function.move-uploaded-file]:无法打开流:没有这样的文件或目录/var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php 第 35 行

警告:move_uploaded_file() [function.move-uploaded-file]:无法将 '/tmp/phptu17Hf' 移动到 '../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg ' 在 /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php 第 35 行

警告:getimagesize(../files/img/galleries/Test/1383204_10200900060289437_410542691_n.jpg) [function.getimagesize]:无法打开流:/var/www 中没有这样的文件或目录/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php 在第 158 行

您的路径中有testTest

请记住,Linux 对文件和文件夹名称是区分大小写的。窗户不是。这或许可以解释为什么它在您的开发环境中有效,以及为什么在您的产品服务器上不再有效。

所以选择其中一个并坚持使用(不过我不建议在路径中使用大写字符)。

【讨论】:

    猜你喜欢
    • 2016-09-26
    • 1970-01-01
    • 2015-07-05
    • 2011-05-23
    • 1970-01-01
    • 2019-07-20
    • 2014-04-16
    • 2012-07-24
    • 2023-04-02
    相关资源
    最近更新 更多