Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 复制图像文件_Php - Fatal编程技术网

Php 复制图像文件

Php 复制图像文件,php,Php,我正在上传一个图像文件,复制它,调整它的大小,然后移动原始文件并调整它的大小 我已经编写了以下函数,我知道有很多空间来整理代码等等 public function useImage($image, $photoid){ $source = $image['tmp_name']; $target = "projectimages/"; //prepare the largest image copy($source, $target); $target

我正在上传一个图像文件,复制它,调整它的大小,然后移动原始文件并调整它的大小

我已经编写了以下函数,我知道有很多空间来整理代码等等

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

}
我遇到了很多错误,但其他错误的关键是我尝试复制或移动上传文件时的第一个错误

Warning: copy(projectimages/) [function.copy]: failed to open stream: Is a directory in /Applications/MAMP/htdocs/bs/classes/image.php on line 171
我在图像上使用了var_dump,看起来图像已经就位了


有什么想法吗?

调用
copy()
的目标是一个目录。尝试按以下方式更改代码:

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

您必须在目标中包含文件名:copy('src/image.jpg','dest/newname.jpg')是的,修复了它,但是现在内存耗尽了!我们必须就此提出一个单独的问题。