【发布时间】:2018-01-30 10:44:06
【问题描述】:
我使用函数crop_compress()来裁剪和压缩图像,然后上传它们
function crop_compress($source_url,$target_file,$qual) {
$image = imagecreatefromjpeg($source_url);
$width = imagesx($image);
$height = imagesy($image);
$thumb_width = $width;
$thumb_height = (9/16)*$width;
.
.
.
$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );
imagejpeg($thumb , $target_file,$qual);
return $target_file;}
$filename= 'crop_compress($_FILES["fileToUpload"]["tmp_name"][$key],$target_fileL,90)'
它工作正常。 现在我想用 ftp 上传这张图片并使用 ftp_put:
ftp_put($connecti,$target_file, $filename, FTP_BINARY);
它也可以正常工作,但它上传了我不想要的 2 次。 我的目录中的一张图片和 ftp 中的一张图片
我的问题是如何避免在我的目录中上传? 我知道 ftp_put() 和crop_compress() 分别上传,但我不知道应该先上传哪个以及如何创建一个 tmp_file 以在另一个或其他东西中获取以避免这个问题?!
更多信息:
$target_dirL = "user"; #in the main host
$tempL=explode(".", $_FILES["fileToUpload"]["name"][$key]);
$target_fileL = $target_dir .$username1. '.' . end($tempL);
$target_dir = "user/$username/"; #another host
$temp=explode(".", $_FILES["fileToUpload"]["name"][$key]);
$target_file = $target_dir .$username1. '.' . end($temp);
$connecti = ftp_connect($anotherHost) or die('Couldn\'t connect to ftp server');
【问题讨论】: