如何从 URL 获取图片 -> 调整大小而不保存 -> 上传到 FTP?
How to get picture from URL -> resize without saving -> upload to FTP?
我有问题!
我可以获取图像并通过 imagecopyresampled()
调整大小。
但是当我尝试使用 ftp_put()
时:期望参数 3 是有效路径。
我尝试使用:
ob_start();
imagejpeg($resource, NULL);
$resource = ob_get_contents();
没用。我不需要将图像保存到本地机器。
使用 FTP protocol wrapper,例如:
imagejpeg($resource, "ftp://user:password@example.com/dir/file.jpg");
更通用的 "upload in-memory contents to FTP" 是:
ob_start();
imagejpeg($resource, NULL);
$contents = ob_get_contents();
file_put_contents("ftp://user:password@example.com/dir/file.jpg", $contents);
另见 Transfer in-memory data to FTP server without using intermediate file。
我有问题!
我可以获取图像并通过 imagecopyresampled()
调整大小。
但是当我尝试使用 ftp_put()
时:期望参数 3 是有效路径。
我尝试使用:
ob_start();
imagejpeg($resource, NULL);
$resource = ob_get_contents();
没用。我不需要将图像保存到本地机器。
使用 FTP protocol wrapper,例如:
imagejpeg($resource, "ftp://user:password@example.com/dir/file.jpg");
更通用的 "upload in-memory contents to FTP" 是:
ob_start();
imagejpeg($resource, NULL);
$contents = ob_get_contents();
file_put_contents("ftp://user:password@example.com/dir/file.jpg", $contents);
另见 Transfer in-memory data to FTP server without using intermediate file。