基本上,当某个页面加载时,我希望能够自动将文件从服务器复制到计算机上的本地目录。这就是我得到的:
<body>
<?php
copy('http://photobooth.josh.com/gsbackgrounds/0001/greenscreen_background.jpg', 'C:'Program Files (x86)'BreezeSys'DSLR Remote Pro'PhotoboothImages'greenscreen_background.jpg');
?>
</body>
但它似乎不起作用。如果我需要在单击时执行此操作,那也可以工作,但我被卡住了。服务器有PHP5,所以我认为这会起作用吗?
执行此操作的简单方法是执行以下操作:
// A simple method requiring allow_url_fopen
$file_contents = file_get_contents($resource_url);
// An alternative method requiring cURL
$ch = curl_init($resource_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$file_contents = curl_exec($ch);
file_put_contents($local_file_path, $file_contents);
我猜copy()
映射到不支持远程项目的系统调用。修改allow_url_fopen标志有可能让它工作,但我对此表示怀疑。
你可以做fopen。
$contents = file_get_contents('http://****.com/file.jpg');
$handle = fopen('yourfilename.jpg',"w");
fwrite($handle,$contents);
fclose($handle);
或者尝试卷曲以加载。
http://phpsense.com/2007/php-curl-functions/
/**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL, ‘http://news.google.com/news?hl=en&topic=t& output=rss’);
/**
* Ask cURL to return the contents in a variable instead of simply echoing them to the browser.
*/
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
/**
* Execute the cURL session
*/
$contents = curl_exec ($ch);
/**
* Close cURL session
*/
curl_close ($ch);
首先,感谢所有试图解决我困境的人,并为延迟回复感到抱歉。
我发现最简单的方法是简单地创建一个javascript函数"Copy",然后在本地机器上单击运行类似批处理文件/wget的程序。它需要Internet Explorer,但这就是我们正在使用的。
无论如何,我只为可能遇到相同问题的其他任何人发布我们的解决方案。再次感谢!