Jump to content

[SOLVED] Photo Gallery


camdes

Recommended Posts

I am trying to create a photo gallery and there are various reasons why I need to create it from scratch. Unfortunately I am very much a beginner and have been using various books and tutorials to try to get this done. Below is the code for my upload file and I have been building it gradually. I have now added the resize function. I had placed this function in a separate PHP file which I called with e require. The function was not found so I embedded it in the file but I get the following errors:

 

Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 68

 

Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 69

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 83

 

Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 90

 

Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 68

 

Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 69

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 83

 

Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 90

Your Photograph was successfully uploaded!

 

Warning: Unexpected character in input: ''' (ASCII=39) state=1 in C:\wamp\www\phototest\reqfiles\image_functions.req.php on line 26

 

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\phototest\reqfiles\image_functions.req.php on line 26

 

Here is my code:

<?php
$uploadid = $_SESSION['loginID'];
$uploaddate = date("j-n-y, G:i:s");

$userfile_name=$HTTP_POST_FILES['userfile']['name'];
$userfile_size=$HTTP_POST_FILES['userfile']['size'];
$userfile_type=$HTTP_POST_FILES['userfile']['type'];

$ph_category=$HTTP_POST_VARS['category'];
$ph_caption=$HTTP_POST_VARS['caption'];

if ($ph_category == "Select Category") {
echo ("You have not selected a category for this photograph<BR>\n");
exit;
}


//check to see if a file is uploaded at all

if ($userfile_size >= 2000000) {
echo ("This file is too large<BR>\n");
echo ("Please reduce the resolution or size of photograph<BR>\n");
echo ("The file size must be below 2 megabytes and try again<BR>\n");
exit;
}

//echo ("upload id: $uploadid<BR>\n");
echo ("upload date: $uploaddate<BR>\n");
echo ("category: $ph_category<BR>\n");
echo ("new file name: $userfile_name<BR>\n");
echo ("caption: $ph_caption<BR>\n");


$photoname="../gallery/$userfile_name";

//check for empty file
echo ("filesize: $userfile_size<BR>\n");

if ($userfile_size==0)
{
echo "Error: File uploaded has no image";
exit;
}

//set upload directory (below) to whatever you need on the server

$photoupfile = "../gallery/$userfile_name";

if ( !copy($userfile, $photoupfile))
{
echo "Error: Could not save file. <br>.mysql_error())";
exit;
}
//report file upload successful!

echo "$photoname uploaded successfully!<br>";

// Resize photographs

function createsmall($name, $filename, $new_w, $new_h){
    $system=explode('.',$name);
    if (preg_match('/jpg|jpeg/',$system[1])){
        $src_img=imagecreatefromjpeg($name);
    }
    if (preg_match('/png/',$system[1])){
        $src_img=imagecreatefrompng($name);
    }
    $old_x=imageSX(src_img);
    $old_y=imageSY($src_img);
    if ($old_x > $old_y) {
        $small_w=$new_w;
        $small_h=$old_y*($new_w/$old_x);
    }
    if ($old_x < $old_y) {
        $small_w=$old_x*($new_w/$old_y);
        $small_h=$new_h;
    }
    if ($old_x == $old_y) {
        $small_w=$new_w;
        $small_h=$new_h;
    }
    $dst_img=ImageCreateTrueColor($small_w,$small_h);
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$small_w,$small_h,$old_x,$old_y);
    if (preg_match('/png/',$system[1])) {
        imagepng($dst_img,$filename);
    } else {
        imagejpeg($dst_img,$filename);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);



createsmall('$photoname','../gallery/images/i_$userfile_name',640,640);
createsmall('$photoname','../gallery/thumbs/t_$userfile_name',70,70);

$new_image=('../gallery/images/i_$userfile_name');
$new_thumb=('../gallery/thumbs/t_$userfile_name');

$query = "INSERT INTO gallery_photos  (photo_filename, photo_thumbnail, photo_caption, photo_category, upload_id, upload_date )". "VALUES ('$new_image','$new_thumb','$ph_caption', '$ph_category','$uploadid','$uploaddate')";

     //echo ("The query is: <BR>$query<P>\n");

if (mysql_db_query ($dbname, $query, $link)){
	echo ("Your Photograph was successfully uploaded!<BR>\n");
} else {
echo(mysql_error());
echo ("Your photograph could not be uploaded.<BR>\n");
}
mysql_close ($link);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.