<form action="" method="post" enctype="multipart/form-data" onsubmit="return SubmitForm(this);">
<input type="text" name="images" value="https://i.hizliresim.com/RJv6qR.jpg"/>
<input type="submit" name="submit" value="Gönder">
</form>
Merhabalar, yukarıdaki gibi bir formum var. form içerisindeki inputa uzak bir kaynaktaki resmin linkini yazıp formu post ediyorum.
post ettiğim formdaki input ta bulunan resmi $_FILES değişkenine atama ve move_uploaded_file fonksiyonuyla upload edebilme gibi bir şansım var mı acaba ?
post ile gelen resmi aşağıdaki fonksiyondan geçmesini istiyorum...
$idx = "5";
$path = "upload/";
$dest = $path.$idx.".jpg";
$source = $_FILES ['images']['tmp_name'];
$tip = $_FILES ['images']['type'];
$image_with = "300";
if ( move_uploaded_file($source, $dest) )
{
if($tip == "image/jpeg")
{
$resim = @imagecreatefromjpeg($dest);
}
else if($tip == "image/png")
{
$resim = @imagecreatefrompng($dest);
}
else if($tip == "image/gif")
{
$resim = @imagecreatefrompng($dest);
}
else
{
return false;
}
$boyutlar = getimagesize($dest);
$resimorani = $image_with / $boyutlar[0];
$yeniyukseklik = $resimorani*$boyutlar[1];
$yeniresim = @imagecreatetruecolor($image_with, $yeniyukseklik);
@imagecopyresampled($yeniresim, $resim, 0, 0, 0, 0, $image_with, $yeniyukseklik, $boyutlar[0], $boyutlar[1]);
!imagejpeg($yeniresim, $dest, 100);
@imagedestroy($yeniresim);
chmod ($dest, 0755);
}
meraktan bizzat şimdi yazıp denedim ve sonuç olumsuz.
move_uploaded_file yerine copy fonksiyonu kullandığımda tmp dizininden dosyayı alabiliyorum.
$tp = fopen('php://input','rb');
$td = tempnam(sys_get_temp_dir(),'rsm');
$tf = fopen($td,'wb');
fwrite($tf,file_get_contents('https://www.r10.net/images/logom7.png'));
stream_copy_to_stream($tp,$tf);
fclose($tp);
fclose($tf);
var_dump(move_uploaded_file($td, dirname(__FILE__).DIRECTORY_SEPARATOR.'test.png'));
$tp = tmpfile();
fwrite($tp,file_get_contents('https://www.r10.net/images/logom7.png'));
var_dump(move_uploaded_file($tp, dirname(__FILE__).DIRECTORY_SEPARATOR.'test.png'));
fclose($tp);