bir klasöre görüntüyü kırpmak ve yüklemek için çalışıyorum

2 Cevap php

i used to do this by uploading the image to the database but later learned its the wrong way because when you try to export the database if ur moving it from localhost to the server the images dont come along :( so anywho, the script i have here is to get the image , crop it, give it a random name and drop it into the gallery folder. but for some reason its not working, and i cant figure it out.. if someone can help me

teşekkürler

if(isset($_POST['submit']) && $_FILES['galleryimg']['size'] > 0) {


$tmpname = $_FILES['galleryimg']['tmp_name'];
$imgsize = $security->secure($_FILES['galleryimg']['size']);
$imgtype = $security->secure($_FILES['galleryimg']['type']);


//crop image
$canvas = imagecreatetruecolor(219,127);
$imgattrib = getimagesize($tmpname);
$source = imagecreatefromjpeg($tmpname);
imagecopyresized($canvas,$source,0,0,0,0,219,127,$imgattrib[0],$imgattrib[1]);
$name = rand(1234,43211234).".png";



ob_start();
imagepng($canvas);
//$image = ob_get_contents();
imagepng($canvas,'/uploads/gallery/'.$name);
ob_end_clean();

}

btw, görüntüleri yüklendikten sonra nasıl ben resimleri görüntülemek için klasörü okunur?

2 Cevap

Her şeyden önce, gerçekten sunucuda bir /uploads/gallery/ var?

Yolunu not, burada, uploads dosya sisteminin kökünde olmalıdır anlamına gelen bir çizgiyle (it is an "absolute" path), tarafından başlar.

Lütfen uploads dizin dosya sisteminin kökünde değil ise, ilk çizgi kaldırmak gerekir; ve / veya göreceli yolunu kullanın; ve / veya gerçek dizine işaret eden bir mutlak yol kullanabilirsiniz.

Belki böyle bir şey geliyordu:

dirname(__FILE__) . '/uploads/gallery/' . $name

Bkz dirname and __FILE__


Once the images are uploaded, you want them to be accessible via HTTP ?

Eğer evet ise, sizin uploads/gallery/ dizini sunucusu için yapılandırılmış belge kök içinde olmalıdır; ve sizin gibi URL'ler ile görüntülere ulaşmak mümkün olacak http://www.example.com/.../uploads/gallery/12345.png


As a sidenote : your second call to imagepng should create a file containing the image ; it shouldn't output anything.

The first one, on the contrary, should display the image... But why are you using this one too, it, if you want to create a file ?
And : if you remove the first (useless ? ) call, you'll be able to remove the output buffering functions too. (anyway, you are not using the information buffered, it seems... so the first call to imagepng is useless, I'd say ? )


If this doesn't help much... What do you mean by this :

but for some reason its not working, and i cant figure it out..

Eğer örneğin, herhangi bir hata var mı?

Bunu kullanmak isteyebilirsiniz:

error_reporting(E_ALL);
ini_set('display_errors', 'On');

senaryonun başında onlar gösterilir, arada: hata mesajları (sen anlamıyorum bazı varsa, bunları eklemek için soruyu düzenlemek olabilir: onlar size yardım etmek faydalı olabilir) yararlı olabilir


This probably won't solve your problem...
But I hope it'll give you some useful pointers...

İyi şanslar!

ob_end_clean Eğer tamponlu bilgilerini atar.

http://us3.php.net/ob%5Fend%5Fclean

Bu deneyin

echo ob_get_clean();