简体   繁体   English

php-调整图片大小并通过ftp上传

[英]php - resizing image and upload it via ftp

Trying to resample one image and upload(reupload) it to my server via ftp. 尝试重新采样一幅图像并通过ftp上传(重新上传)到我的服务器。 I've ftp access, so no conection problems here, but my file doesn't go there because imagecopyresized handle is a number (1) and not a file. 我具有ftp访问权限,因此这里没有连接问题,但是我的文件没有到那里,因为imagecopyresized的句柄是数字(1)而不是文件。

The question is, what should i do with this litle code 问题是,我应该如何处理这个代码

imagejpeg($background,ftp_put($conn_id, $destino, imagecopyresized($background, $im, 0, 0, 0, 0, $nw, $nh, $w, $h), FTP_BINARY),99);

Thanks, 谢谢,

Pluda 普鲁达

save that image to file and then send it 将该图像保存到文件,然后发送

$servername = "8.8.8.8";
$ftpUser = "user";
$ftpPass = "pass";
$conn = ftp_connect($servername) or die("Error connecting to $servername");

if(ftp_login($conn, $ftpUser, $ftpPass))
{
            ftp_put($conn_id, "image.jpg", $file);
}

You can use an output buffer to capture the output of imagejpeg and the send it in ftp: 您可以使用输出缓冲区捕获imagejpeg的输出并将其发送到ftp:

imagecopyresized($background, $im, 0, 0, 0, 0, $nw, $nh, $w, $h);

ob_start();
imagejpeg($background, NULL, 99);
$background = ob_get_contents();
ob_end_flush();

ftp_put($conn_id, $destino, $background, FTP_BINARY);

ftp_put - third parameter for this function must be path to local file. ftp_put-此函数的第三个参数必须是本地文件的路径。

So you should save image to local and then try to use ftp_put function 因此,您应该将映像保存到本地,然后尝试使用ftp_put函数

$local_file = '/tmp/temp.jpg';

if ( imagecopyresized($background, $im, 0, 0, 0, 0, $nw, $nh, $w, $h) ) 
{
    if ( imagejpeg($background, $local_file) ) 
    {
        if ( ftp_put($conn_id, $destino, $local_file, FTP_BINARY) ) 
        {
            unlink($local_file)
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM