带有URL的file_get_contents

时间:2015-06-11 17:38:54

标签: php parse-platform

我正在使用Parse并尝试从网址获取图片并将其另存为ParseFile

我成功地将本地上传的图片保存为ParseFile。如何使用图片网址执行相同操作?

echo $_POST['imageURL']; // url to image
// successfully saves uploaded image
// $file = ParseFile::createFromData( file_get_contents( $_FILES['image']['tmp_name'] ), $_FILES['image']['name']  );

// trying to save image from URL
$file = ParseFile::createFromData( file_get_contents( $_POST['imageURL'] ), $_FILES['image']['name']  );

$file->save();

这是我得到的错误:

https://www.webniraj.com/wp-content/uploads/2012/05/WNI01_14-Logo-275x63.png
Fatal error: Call to a member function save() on a non-object in /var/www/html/quickupload/upload.php on line 96

1 个答案:

答案 0 :(得分:0)

尝试此功能

function get_url_content($URL){
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_URL, $URL);
          $data = curl_exec($ch);
          curl_close($ch);
          return $data;
      }

$file =  get_url_content('http://example.com/logo.jpg');