duangaixing1509 2013-09-04 21:41
浏览 67
已采纳

PHP - 将图像资源上传到FTP

I'm trying to resize image and upload it to FTP server without saving it on local disc but I didn't find any method how to do that. Function ftp_fput obviously doesn't TAKE image resource as argument.

I'm trying to do this:

imagecopyresampled($canvas, $image, 0, 0, 0, 0, $width, $height, $oldWidth, $oldHeight);

ob_start();
imagejpeg($canvas);
$stream = ob_get_clean();

// ftp_->fput(imagecreatefromstring($stream));
ftp_->fput($stream);

Any help?

  • 写回答

1条回答 默认 最新

  • doushi1957 2013-09-04 21:55
    关注

    PHP doesn't have a function to write a string through ftp. You would have to write the file to disk and send it or you can use the php://memory or php://temp wrapper to write the data to memory and pass that to ftp_fput. There is a comment on the ftp_put manual page that has a simple function that flushes to a temp file.

    http://www.php.net/manual/en/function.ftp-put.php#83260

    There are a few comments on the ftp_fput manual page that cover this as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?