参见英文答案 >
Saving image from PHP URL9个
我有以下代码:
我有以下代码:
$file = 'http://3.bp.blogspot.com/-AGI4aY2SFaE/Tg8yoG3ijTI/AAAAAAAAA5k/nJB-mDhc8Ds/s400/rizal001.jpg'; $newfile = '/img/submitted/yoyo.jpg'; if ( copy($file,$newfile) ) { echo "Copy success!"; }else{ echo "Copy Failed."; }
并且它总是输出“复制失败”
copy(/img/submitted/yoyo.jpg) [function.copy]: Failed to open stream: No such file or directory
我的目录设置为777.
有任何想法吗?谢谢!
而
原文链接:https://www.f2er.com/php/140143.htmlcopy()
将接受一个URL作为源参数,它可能会出现一个目标网址.
您是否尝试指定输出文件的完整文件系统路径?我假设你不想将新文件放在远程服务器上.
例如:
$file = 'http://3.bp.blogspot.com/-AGI4aY2SFaE/Tg8yoG3ijTI/AAAAAAAAA5k/nJB-mDhc8Ds/s400/rizal001.jpg'; $newfile = $_SERVER['DOCUMENT_ROOT'] . '/img/submitted/yoyo.jpg'; if ( copy($file,$newfile) ) { echo "Copy success!"; }else{ echo "Copy Failed."; }
以上对我来说很好.