我正在修改此插件以保存路径记录并制作缩略图并保存http://bakery.cakephp.org/articles/srs2012/2012/03/12/ajaxmultiupload_plugin_for_cake_2_0_x_and_2_1 我修改了upload.php像这样的插件:
function save($path, $folder, $filename) {
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
if ($realSize != $this->getSize()){
return false;
}
$width = 290;
$height = 146;
$target = fopen($path, "w");
//$this->Upload->setImage($this->Image);
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
$val = $this->resizeImage($filename, $filename, $folder, $folder.'/small/', $width, $height, 100);
$this->saveToDatabase(array('path' => $folder.$filename, 'thumb' => $folder.'/small/'.$filename));
return true;
}
这是我保存的功能:
function saveToDatabase($data){
$this->Image->save($data);
}
我添加以下内容以创建缩略图:
function resizeImage($src_img, $dst_img, $src_path2, $dst_path2, $dst_w, $dst_h, $dst_quality){
//Stop and giving an error if the file does not exists.
$src_path = 'img/';
$dst_path = 'img/';
$src_path .= $src_path2;
$dst_path .= $dst_path2;
if(file_exists($src_path . basename($src_img)) == false){
echo 0;
}
//Get variables for the function.
//complete path of the source image.
$src_cpl = $src_path . basename($src_img);
//return $src_cpl;
//complete path of the destination image.
$dst_cpl = $dst_path . basename($dst_img);
//extension excl "." of the source image, in lowercase.
$src_ext = strtolower(end(explode(".", $src_img)));
//width and height sizes of the source image.
list($src_w, $src_h) = getimagesize($src_cpl);
//get type of image.
//return 'IETS: '.$src_cpl.' :IETS';
$src_type = exif_imagetype($src_cpl);//
//Checking extension and imagetype of the source image and path.
if( ($src_ext =="jpg") && ($src_type =="2") ){
$src_img = imagecreatefromjpeg($src_cpl);
}else if( ($src_ext =="jpeg") && ($src_type =="2") ){
$src_img = imagecreatefromjpeg($src_cpl);
}else if( ($src_ext =="gif") && ($src_type =="1") ){
$src_img = imagecreatefromgif($src_cpl);
}else if( ($src_ext =="png") && ($src_type =="3") ){
$src_img = imagecreatefrompng($src_cpl);
}else{
die('<p>The file "'. $src_img . '" with the extension "' . $src_ext . '" and the imagetype "' . $src_type . '" is not a valid image. Please upload an image with the extension JPG, JPEG, PNG or GIF and has a valid image filetype.</p>');
}
//Get heights and width so the image keeps its ratio.
$x_ratio = $dst_w / $src_w;
$y_ratio = $dst_h / $src_h;
if( (($x_ratio > 1) || ($y_ratio > 1)) && ($x_ratio > $y_ratio) ){
//If one of the sizes of the image is smaller than the destination (normal: more height than width).
$dst_w = ceil($y_ratio * $src_w);
$dst_h = $dst_h;
}elseif( (($x_ratio > 1) || ($y_ratio > 1)) && ($y_ratio > $x_ratio) ){
//If one of the sizes of the image is smaller than the destination (landscape: more width than height).
$dst_w = $dst_w;
$dst_h = ceil($x_ratio * $src_h);
}elseif (($x_ratio * $src_h) < $dst_h){
//if the image is landscape (more width than height).
$dst_h = ceil($x_ratio * $src_h);
$dst_w = $dst_w;
}elseif (($x_ratio * $src_h) > $dst_h){
//if the image is normal (more height than width).
$dst_h = ceil($x_ratio * $src_h);
$dst_w = $dst_w;
}else{
//if the image is normal (more height than width).
$dst_w = ceil($y_ratio * $src_w);
$dst_h = $dst_h;
}
// Creating the resized image.
$dst_img=imagecreatetruecolor($dst_w,$dst_h);
$result = imagecopyresampled($dst_img,$src_img,0,0,0,0,$dst_w, $dst_h,$src_w,$src_h);
// Saving the resized image.
$result2 = imagejpeg($dst_img,$dst_cpl,$dst_quality);
return 'dfdfhdfhhgfddghhgffddghdghhdgghgfhdh: '.$result.'|||asdasda'.$result2;
// Cleaning the memory.
imagedestroy($src_img);
imagedestroy($dst_img);
}
enter code here
现在我已经在同一台服务器上使用了这段代码,它运行得非常好。但在我的返回值中,我得到以下信息:
[uploader] responseText = dfdfhdfhhgfddghhgffddghdghhdgghgfhdh: 1|||asdasda{"success":true}
函数 imagejpeg 不返回任何内容。
现在可能出了什么问题?我只是一个实习生,我不知道出了什么问题。
问候,伤害。撞?