PHPファイルを使用してURLから自分のコンピュータに画像を保存しようとしています。私が検索したカードが1つの名前しか持たないときに動作します。しかし、私がしようとすると、複数の名前を持つカードのためにそれを行うには、私が取得:PHPを使用したURLから画像をディスクに保存する
Warning: file_get_contents(http://gatherer.wizards.com/Handlers/Image.ashx?name=black lotus&type=card&.jpg): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in C:\xampp\htdocs\MTGFetcher\results.php on line 6
ここに私のcardfetch.phpための私のコードです。
<form action="results.php" method="post">
Name of card: <br>
<input type="text" name="cardname" value="cardresult">
<input type="submit" value="Submit">
</form>
そして、私のresults.php用:
<?php
$results = $_POST['cardname'];
$url = "http://gatherer.wizards.com/Handlers/Image.ashx?name=" . $results . "&type=card&.jpg";
$img = "Pictures/$results.jpg";
file_put_contents($img, file_get_contents($url));
?>
<img src="<?php echo $url ?>">
は、なぜそれが複数の単語で作業されていませんか?
ありがとうございました! –