I am trying to create a photo gallery and there are various reasons why I need to create it from scratch. 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 error:
Parse error: syntax error, unexpected $end in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 114 (this is the last line of my file) Can someone help with 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);
?>

You don't seem to close off your function at the end. This is why you're getting an $end parse error.

Thank you for that, I have now closed the function and get:
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

You need to open your image using something like this:

$tmpName  = $HTTP_POST_FILES['userfile']['tmp_name'];

$fp= fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

then use the $content variable to store/modify, as it is your actual image. Also, i'm using tmp_name because it allows us to use a temporary clone of the original image for safetys sake.

There were a lot of errors there, so hopefully that gets rid of the invalid image ones.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.