質問

私は個人的な使用のためのページを作成しようとしています。私がやりたいのは、ローカルハードディスクに画像をダウンロードできるシステムを作成して、リンクを介して直接提供することです。 localhost ワンプのように。私がやろうとしている理由は、画像をハードディスクに自動的にソートしたいからです。私のフォームフィールドはこのようなものになります

<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

OK、代わりにカールを使用して、期待していることを達成しました。これがコードです

$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 and yourに当てはまります 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);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top