tags:

views:

50

answers:

2

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

thanks

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, once the images are uploaded how do i read the folder to display the images?

A: 

ob_end_clean discards the information you buffered.

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

Try this

echo ob_get_clean();
jW
+1  A: 

First of all, do you really have a /uploads/gallery/ on your server ?

Note the path, here, begins by a slash (it is an "absolute" path), which means uploads must be at the root of the filesystem.

If your uploads directory is not at the root of the filesystem, you should remove the first slash ; and/or use a relative path ; and/or use an absolute path that points to the real directory.

Maybe you meant something like this :

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

See dirname and __FILE__


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

If yes, your uploads/gallery/ directory must be inside the document root configured for your server ; and you'll be able to access the images with URLs like 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..

Do you have any error, for instance ?

You might want to use this :

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

at the beginning of your script so they are displayed, btw : the error messages could be useful (if you have some that you don't understand, you could edit your question to add them : they might be useful to help you)


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

Good luck !

Pascal MARTIN