이것은 서버에 외부 이미지를 저장하는 코드입니다. 작동합니다.
$imgfromurl = file_get_contents('http://www.lavanguardia.com/r/GODO/LV/p4/WebSite/2017/03/07/Recortada/img_lbernaus_20170307-110204_imagenes_lv_terceros_istock-578792430-kUN-U42609284081yLC-992x558@LaVanguardia-Web.jpg');
$im = imagecreatefromstring($imgfromurl);
$width = imagesx($im);
$height = imagesy($im);
$newwidth = $width/2;
$newheight = $height /2;
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$newsimgpath = uniqid().'.jpg';
$imgjpeg = imagejpeg($thumb, $newsimgpath); //save image as jpg
imagedestroy($thumb);
imagedestroy($im);
하지만 이미지를 폴더에 저장하려면 더 이상 작동하지 않습니다.
나는 이것을 변경하려고 시도했습니다.
$imgjpeg = imagejpeg($thumb, $newsimgpath);
이에
imagejpeg($thumb, '/imgnews/'.$newsimgpath);
또는 이것에 :
imagejpeg($thumb, realpath(dirname(__FILE__)).'/imgnews/'.$newsimgpath);
그러나 이미지는 해당 폴더에 저장되지 않습니다 (권한 777가 있음).
왜 ?
편집하다:
오류 기록:
[10-Mar-2017 08:52:32 America/New_York] PHP Warning: imagejpeg(/home/xxx/public_html/imgnews/58c2afa0c2c4b.jpg): failed to open stream: No such file or directory in /home/xxx/public_html/ad.php on line 14
오류에서 볼 수 있듯이-해당 디렉토리가 없습니다.
이미지에서 볼 수 있듯이 http://i.imgur.com/MoKGyF6.png 에는 newsimg 디렉토리가 있습니다.
두 가지 옵션이 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다