是否可以将图像从网络复制到硬盘驱动器?
-
11-10-2019 - |
题
我正在尝试创建一个仅供个人使用的页面。我想做的是创建一个系统,可以直接通过通过一个提供链接将图像下载到本地硬盘 Localhost 像Wamp。我要做的原因是,我希望将图像自动在硬盘上排序。我的表格字段将是这样的
<form method="POST" action="process.php">
<input type="text" name="URL" id="URL" />
<input type="text" name="category" id="category" />
<input type="text" name="subcategory" id="category" />
<input type="submit">
</form>
现在,在 process.php
//This is just a sample... So please ignore the roughness of the coding
copy($_POST['url'],$_POST['category']."/".$_POST['subcategory']."/somename.jpg");
// If you noticed, the categories and subcategories are actually the name of directory, where I want the picture to go be saved....
我认为我的方法是错误的。我该如何实现这样的目标?
错误
Warning: copy(images/image.jpg) [function.copy]: failed to open stream: No such file or directory in
解决方案 2
好的,我使用卷曲来实现我的期望。这是代码
$img = $_POST['url'];
$fullpath = $_POST['category']."/".$_POST['subcategory']."/".basename($img);
$ch = curl_init ($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec($ch);
curl_close ($ch);
$fp = fopen($fullpath,'x');
fwrite($fp, $rawdata);
其他提示
如果 allow_url_fopen
在php.ini和您的 PHPVERSION
IS> = 4.3.0您的代码应起作用。
您可以从指定的URL中首先从PHP脚本文档下载,然后给出HTTP-CLIENT链接以下载本地存储的文件。或将文档内容输出流:
$cont = file_get_contents($_GET['url']);
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: binary ");
header('Accept-Ranges: bytes');
header('Content-disposition: attachment; filename=' . $new_file_name));
echo($cont);
不隶属于 StackOverflow