OK, nothing I've tried thus far has even remotely worked.
I have to create a unique name for the image. I would like to use the user's user_id to do this. This way I can identify the photo as belonging to whomever.
The images aren't stored in the database, just the name and sizes. But the image_name in the database will be the same as the image names of the photos in the folders - pgallery/ and pgallery/thumbs, and will be used in a script to display the images.
Ideally the image name would look like this in the database and in the folders:
12_boat.jpg - where 12 is the person's user_id. But how to do this?
Here's the image script:
- if(isset($_POST['submit'])){
-
if (isset ($_FILES['new_image'])){
-
$imagename = $_FILES['new_image']['name'];
-
$source = $_FILES['new_image']['tmp_name'];
-
-
$target = "./../pgallery/".$imagename;
-
move_uploaded_file($source, $target);
-
-
$imagepath = $imagename;
-
-
$save = "./../pgallery/" . $imagepath; //This is the new file you saving
-
$file = "./../pgallery/" . $imagepath; //This is the original file
-
-
list($width, $height) = getimagesize($file) ;
-
-
$b_width = 640;
-
$b_height = 480;
-
-
-
if($width > $height)
-
{
-
$diff = $width / $b_width;
-
$b_height = $height / $diff;
-
-
}
-
elseif($height >= $width)
-
{
-
$diff = $height / $b_height;
-
$b_width = $width / $diff;
-
}
-
-
-
-
-
$tn = imagecreatetruecolor($b_width, $b_height) ;
-
$image = imagecreatefromjpeg($file) ;
-
imagecopyresampled($tn, $image, 0, 0, 0, 0, $b_width, $b_height, $width, $height) ;
-
-
imagejpeg($tn, $save, 100) ;
-
-
$save = "./../pgallery/thumbs/" . $imagepath; //This is the new file you saving
-
$file = "./../pgallery/" . $imagepath; //This is the original file
-
-
list($b_width, $b_height) = getimagesize($file) ;
-
-
$t_width = 100;
-
$t_height = 100;
-
-
-
if($b_width > $b_height)
-
{
-
$diff = $b_width / $t_width;
-
$t_height = $b_height / $diff;
-
-
}
-
elseif($b_height >= $b_width)
-
{
-
$diff = $b_height / $t_height;
-
$t_width = $b_width / $diff;
-
}
-
-
-
-
-
$tn = imagecreatetruecolor($t_width, $t_height) ;
-
$image = imagecreatefromjpeg($file) ;
-
imagecopyresampled($tn, $image, 0, 0, 0, 0, $t_width, $t_height, $b_width, $b_height) ;
-
-
imagejpeg($tn, $save, 100) ;
-
What this script does is take a large image file and reduce it in size. It is this reduced image that is put in the pgallery folder and is used to create the thumbnail image that will go into the pgallery/thumbs folder.