【问题标题】:how to avoid duplicate upload in php?如何避免在php中重复上传?
【发布时间】: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'); 

【问题讨论】:

    标签: php ftp upload


    【解决方案1】:

    ftp_put($connecti,$target_file, $filename, FTP_BINARY);之后使用unlink( $filename );

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

    【讨论】:

    • 我考虑了一下,但一开始没有办法避免上传?
    • @hameds1 你是什么意思?我不明白你避免上传是什么意思。请解释清楚。
    • 此代码在两个位置上传图像。一个在主主机的根目录,另一个在 ftp 主机。我只想在 ftp 主机中使用 ftp 上传
    • @hameds1 请显示$connecti,$target_file, $filename的代码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多