Langkiller
Langkiller

Reputation: 3457

PHP's file upload is failing on server

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.

Upvotes: 0

Views: 240

Answers (1)

D4V1D
D4V1D

Reputation: 5849

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

Upvotes: 1

Related Questions