Search code examples
phpuploadresize-image

Warning: getimagesize(image.jpg) [ ]: failed to open stream: no such file or directory


I have problem to crop the image, but this source work fine when i use for resize image before some code i change to crop.

This the source for Crop:

$filenames1 = stripslashes($_FILES['txtfile1']['name']);
$exts1 = substr($images1, strrpos($images1, '.')+1);
$idimgs = md5(uniqid() . time() . $filenames1) . "-1." . $exts1;
$target_files1 = $target_dir . basename($idimgs);

    list($width, $height) = getimagesize($filenames1);

    $realImages             = imagecreatefromjpeg($_FILES['txtfile1']['tmp_name']);

    if ($width > $height) {
    $y = 0;
    $x = ($width - $height) / 2;
    $smallestSide = $height;
    } else {
    $x = 0;
    $y = ($height - $width) / 2;
    $smallestSide = $width;
    }

    $thumbSize     = 200;

    $thumbImage = imagecreatetruecolor($thumbSize, $thumbSize);
    imagecopyresampled($thumbImage, $realImages, 0,0,$x,$y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);

    imagejpeg($thumbImage,$target_dir.$idimgs);

    imagedestroy($realImages);
    imagedestroy($thumbImage);

How to fix this?


Solution

  • php can't access files from client system directly. Here you are trying to access $_FILES['txtfile1']['name'] instead try getimagesize($_FILES['txtfile1']['tmp_name'])