且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从URL保存图像,然后将其保存到目录php

更新时间:2023-09-05 13:32:52

您应该可以为此使用file_get_contents.为了在file_get_contents中使用URL,请确保在php.ini文件中启用了allow_url_fopen.

You should be able to use file_get_contents for this one. In order to use an URL with file_get_contents make sure allow_url_fopen is enabled in you php.ini file.

define('DIRECTORY', '/home/user/uploads');

$content = file_get_contents('http://anothersite/images/goods.jpg');
file_put_contents(DIRECTORY . '/image.jpg', $content);

确保对要存储图像的目录具有写权限;要使该文件夹可写,您可以执行以下操作:

Make sure that you have write permission to the directory where you want to store the image; to make the folder writable you could do this:

chmod +w /home/users/uploads

参考

  1. file_get_contents
  2. allow_url_fopen
  3. chmod命令
  1. file_get_contents
  2. allow_url_fopen
  3. chmod command