如何避免在php中重复上传?

如何避免在php中重复上传?,php,ftp,upload,Php,Ftp,Upload,我使用函数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; . . .

我使用函数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\u put:

ftp_put($connecti,$target_file, $filename,  FTP_BINARY);
它的工作也很好,但它上传了2次,我不想。 一个映像在我的目录中,另一个带有ftp

我的问题是如何避免上传到我的目录? 我知道ftp_put()和crop_compress()分别上传,但我不知道哪一个应该放在第一位,以及如何创建tmp_文件以在另一个或其他文件中进行源以避免此问题

更多信息:

$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'); 
使用
取消链接($filename)
ftp\u put之后($connecti,$target\u file,$filename,ftp\u二进制文件)


这将在通过FTP上传文件后删除该文件。

我考虑过,但一开始没有办法避免上传?@hameds1什么意思?我不明白你回避上传是什么意思。请更好的解释。这个代码上传图像在两个位置。一个在主主机的根目录中,另一个在ftp主机上。我只想上传ftp中的ftphost@hameds1请显示
$connecti、$target\u file、$filename的代码