我尝试使用网址将文件(png)上传到我的网站目录:
$url = "http://api.qrserver.com/v1/create-qr-code/?data=hello_word&size=100x100";
$file = file_get_contents($url);
$fileName = "filename";
$dir = $this->get('kernel')->getRootDir() . '/../web/uploads/img';
$file->move( $dir , $fileName);
警告:file_get_contents(http://api.qrserver.com/v1/create-qr-code/?data=hello_word&size=100x100):无法打开流:HTTP请求失败! HTTP / 1.1 400错误请求
答案 0 :(得分:1)
$fileName = "filename";
$dir = $this->get('kernel')->getRootDir() .
'/../web/uploads/img'.$fileName;
$ch = curl_init('http://api.qrserver.com/v1/create-qr-code/?
data=hello_word&size=100x100');
$fp = fopen($dir, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
尝试类似的东西。如果这不起作用我会考虑使用。 http://php.net/manual/en/function.file-put-contents.php
答案 1 :(得分:0)
file_get_contents
将返回一个字符串。file_get_contents
。file_put_contents
函数。