简体   繁体   English

无法打开流:没有这样的文件或目录

[英]Failed to open stream: No such file or directory

Hi i am new to php and i am working on image upload and crop and save bth upload and cropped image in zend on windows 7 but it's giving me these errors. 嗨,我是php的新手,我正在处理图像上传和裁剪,并在Windows 7上保存bth上传和裁剪图像,但它给了我这些错误。 Please help me to solve these errors. 请帮我解决这些错误。

Warning: imagecreatefromjpeg(public/image/) [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: failed to open stream: No such file or directory in C:\\wamp\\www\\ModuleEx.com\\application\\modules\\admin\\controllers\\IndexController.php on line 64

Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in C:\\wamp\\www\\ModuleEx.com\\application\\modules\\admin\\controllers\\IndexController.php on line 68

Warning: imagejpeg() [<a href='function.imagejpeg'>function.imagejpeg</a>]: Unable to open 'public/image/crop/' for writing: No such file or directory in C:\\wamp\\www\\ModuleEx.com\\application\\modules\\admin\\controllers\\IndexController.php on line 71

Here is my controller.php code. 这是我的controller.php代码。

if(isset($_FILES['file']['name'])){ //user upload file
    $file_name = stripslashes($_FILES['file']['name']);
    $ext_idx = strrpos($file_name,".");
    if(!$ext_idx) //hide this if ur app can upload without ext
        echo "File invalid.";
    else{
        $ext_length = strlen($file_name) - $ext_idx;
        $extension = strtolower(substr($file_name,$ext_idx+1,$ext_length));
        //allowed extension
        $ext_list = array("pdf", "doc","jpg", "jpeg", "gif", "png");
        if(!in_array($extension, $ext_list))
            echo "System can't support your extension.";
        else{
            $size = (2500 * 1024); //2500 Kb
            $file_size=filesize($_FILES['file']['tmp_name']);
            if($file_size > $size)
                echo "File is oversize. Max 2500 Kb.";
            else{
                //change name
                $file_name = "image".rand(10,1000).".".$extension;

                $file_obj="public/image/".$file_name;



                $copied = copy($_FILES['file']['tmp_name'], $file_obj);

                if(!$copied)
                    echo "Failed.";
                else 
                {

                    $file_data = array( 'file_name' => $file_name );


                    $this->view->file_obj=$file_obj;




                }
                }

            }
        }
    }
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
 $targ_w = $targ_h = 150;
 $jpeg_quality = 90;
 $src = "public/image/".$file_name;

$img_r = imagecreatefromjpeg($src);
 $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

 imagecopyresampled($dst_r,$img_r,0,0,(int)$_POST['x'],(int)$_POST['y'],
 $targ_w,$targ_h,(int)$_POST['w'],(int)$_POST['h']);

//header('Content-type: image/jpeg');
  imagejpeg($dst_r,"public/image/crop/".$file_name,$jpeg_quality);

   }

Look at this "imagecreatefromjpeg(public/image/)" - this is NOT a image resource. 看看这个“imagecreatefromjpeg(public / image /)” - 这不是图像资源。 It only works with a valid file resource like 它只适用于有效的文件资源

imagecreatefromjpeg('public/image/test.jpg');

try this code: 试试这段代码:

    $a="./images/".$file_name;
    list($width, $height) = getimagesize($a);
    $newwidth = "300"; 
    $newheight = "200";
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    $source = imagecreatefromjpeg($a);
    imagecopyresized($dest, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    imagejpeg($dest, $a, 100);
Warning: imagecreatefromjpeg(public/image/)

your path is not correct you should use the absolute path with __DIR__ for example. 你的路径不正确你应该使用__DIR__的绝对路径。

imagecreatefromjpeg(__DIR__."public/image/test.jpg");

and your filename is missing. 并且您的文件名丢失了。 The next errors result from the first error that your image can't load. 下一个错误是由于您的图像无法加载的第一个错误导致的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM