开发者

php - resizing image and upload it via ftp

Trying to resample one image and upload(reupload) it to my server via 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.

开发者_高级运维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);
}


ftp_put - third parameter for this function must be path to local file.

So you should save image to local and then try to use ftp_put function

$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)
        }
    }
}


You can use an output buffer to capture the output of imagejpeg and the send it in 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜