dongshadu4498 2014-03-20 16:07
浏览 12
已采纳

复制图像文件

I'm uploading an image file, copying it, resizing it, then moving the original file and resizing it!

I've written the following function, I know there's a lot of room to tidy the code up etc.

public function useImage($image, $photoid){

    $source = $image['tmp_name'];
    $target = "projectimages/";

    //prepare the largest image

    copy($source, $target);
    $targetname = $photoid."large.jpg";
    $file = $target.$targetname;

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

    $modwidth = 800;

    $diff = $width / $modwidth;

    $modheight = $height / $diff;
    $tn = imagecreatetruecolor($modwidth, $modheight);
    $image = imagecreatefromjpeg($file);
    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);

    imagejpeg($tn, $file, 100);

    //prepare the smaller image

    move_uploaded_file($source, $target);
    $targetname = $photoid."small.jpg";
    $file = $target.$targetname;

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

    $modwidth = 400;

    $diff = $width / $modwidth;

    $modheight = $height / $diff;
    $tn = imagecreatetruecolor($modwidth, $modheight);
    $image = imagecreatefromjpeg($file);
    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);

    imagejpeg($tn, $file, 100);

}

I'm getting plenty of errors but the crucial one that the others are built upon is the first one when I try and copy or move the uploaded file...

Warning: copy(projectimages/) [function.copy]: failed to open stream: Is a directory in /Applications/MAMP/htdocs/bs/classes/image.php on line 171

I've used var_dump on image and it appears the image is in place.

Any ideas?

  • 写回答

1条回答 默认 最新

  • duandange7480 2014-03-20 16:11
    关注

    The destination of the copy() call is a directory. Try to change your code like this:

    $source = $image['tmp_name'];
    $target = "projectimages/";
    
    //prepare the largest image
    
    $targetname = $photoid."large.jpg";
    $file = $target.$targetname;
    copy($source, $file);
    
    // The rest of your code goes here.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式