phpfile-uploaduploadmove-uploaded-file

Can't upload a file (no error, zero size)


I have any troubles with file upload, with JPG files. But not with all, I don't find any reason... :-( And of course, I tried to search first, but no results...

I have an image, printscreen from website, opened and saved in Photoshop as JPG with no compression, 100 quality. It's normally working in Mac Finder, I can open the image, it seems to be not corrupted (have you ever seen corrupted printscreen :-) ). When I have another one image (JPG), open it in Photoshop, resave and try to upload, file is uploaded correctly.

Upload script is shortened to this code

$files = [$_FILES['image'], $_FILES['imageHP']];
foreach ($files as $src) {
    $path = '';
    $name = prettyname($src['name']) . '-' . substr(time(), -4) . '.' . strtolower(pathinfo($src['name'], PATHINFO_EXTENSION)); // prettyname just make cool image name, strtolower, no spaces, accents, etc.
    if (!move_uploaded_file($src['tmp_name'], __DIR__ . "/../uploads/" . $path . 'orig_' . $src['name'])) {
        die ('Corrupted file'); // without this condition it the same
    }
}

After uploading a file(s) I sometimes gets

Array
(
    [image] => Array
        (
            [name] => centrum.jpg
            [type] => image/jpeg
            [tmp_name] => /private/var/tmp/phpzDyQE4 // file should be uploaded?
            [error] => 0           // strange error = 0
            [size] => 0            // strange, size = 0
        )

)

When I try to upload another one image, the dump is correct and file is uploaded.

Array

(
    [image] => Array
        (
            [name] => team.jpg
            [type] => image/jpeg
            [tmp_name] => /private/var/tmp/phpc5wmkE
            [error] => 0       // no error
            [size] => 601807   // correct file size
        )

Any idea? Thanks


Solution

  • It seems like a problem with cache. Try to clear cache out, remove temporary files, etc.