0

我正在尝试创建一个仅供个人使用的页面。我想要做的是,创建一个系统,通过它我可以将图像下载到我的本地硬盘,直接通过像 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
4

3 回答 3

1

好的,我使用 curl 来实现我的期望。这是一段代码

$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);
于 2011-01-07T06:19:59.500 回答
1

如果allow_url_fopen在 php.ini 中为真并且您的PHPVERSION为 >= 4.3.0,则您的代码应该可以工作。

于 2010-12-20T10:46:48.097 回答
0

you can first download from php script document from specified url, then give http-client link to download locally stored file. or put document content to output stream:

 $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);
于 2010-12-20T10:49:44.320 回答