2016-10-14 22 views
1

ように私はPHPスクリプトの出力.jpgファイルとして生成された画像を持ってしてみてください。 image.jpgは保存されません。保存画像出力は、ファイル

どうすればこの作品を作成できますか?

+0

使用しています。 'header( 'Content-Type:image/jpeg');'。これに続くhttp://php.net/manual/en/function.imagejpeg.php url –

+0

ini設定の確認echo ini_get( 'allow_url_fopen'); –

+0

$ url = "http://www.domain.com/showphoto.php?photo=10" URLに画像がありません –

答えて

1

サーバーが送信しているファイルの種類をブラウザが理解できるように、適切なMIMEタイプのContent-Typeヘッダーを出力する必要があります。

header('Content-Type: image/jpeg'); 

は有効なMIMEタイプのリストについてはhttp://php.net/manual/en/function.header.phphttps://www.sitepoint.com/web-foundations/mime-types-complete-list/を参照してください。

+0

私は試しました:code <?php header( 'Content-Type:image/jpeg'); $ url = 'http://www.photopost.com/photopost/showfull.php?photo=7541';file_put_contents( 'image.jpg'、file_get_contents($ url)); ?> – Matthijs

+0

ですが、ブラウザにエラーが表示されます。 – Matthijs

+0

画像を保存するパスを指定しましたか? (つまり、 'file_put_contents( '/ tmp/image.jpg'、$ data);') デフォルトのパスは、おそらくWebサーバーによって書き込み可能ではありません。 Webサーバー/ PHPプロセスがそのパスに書き込むことはできますか?お手伝いをさせていただくためには、エラーを提供する必要があります。 – Janek

0

使用したURLから画像を取得するカール: -

$profile_Image = 'http://www.photopost.com/photopost/showfull.php?photo=7541'; //image url 
$userImage = 'myimg.jpg'; // renaming image 
$path = ''; // your saving path 
$ch = curl_init($profile_Image); 
$fp = fopen($path . $userImage, 'wb'); 
curl_setopt($ch, CURLOPT_FILE, $fp); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
$result = curl_exec($ch); 
curl_close($ch); 
fclose($fp); 

は、のfile_get_contentsを使用したURLから画像を取得する: -

$profile_Image = 'http://www.photopost.com/photopost/showfull.php?photo=7541'; //image url 
$userImage = 'myimg.jpg'; // renaming image 
$path = ''; // your saving path 
$thumb_image = file_get_contents($profile_Image); 
if ($http_response_header != NULL) { 
    $thumb_file = $path . $userImage; 
    file_put_contents($thumb_file, $thumb_image); 
} 
+0

こんにちはJinandra、あなたの助けのためのthansk。このコードは、有効なjpgとして私のPC上で認識されないファイルをダウンロードします! – Matthijs

0

がに

http://www.photopost.com/photopost/showfull.php?photo=7541 //html document 

からあなたのURLを変更

http://www.photopost.com/photopost/watermark.php?file=7541 //downloadable url 

そして、他の回答からコードを使用するか、あなたは私が考えるヘッダーを設定する必要がimagecreatefromjpeg http://php.net/manual/en/function.imagecreatefromjpeg.php

+0

Daveありがとう、これは動作します! (私の投票はまだ低い評判のために見えない) – Matthijs