•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,424 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,384 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 488 | Replies: 3 | Solved
![]() |
•
•
Join Date: Mar 2008
Posts: 12
Reputation:
Rep Power: 1
Solved Threads: 0
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.
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);
?>•
•
Join Date: Mar 2008
Posts: 12
Reputation:
Rep Power: 1
Solved Threads: 0
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
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
•
•
Join Date: Apr 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 2
You need to open your image using something like this:
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.
php Syntax (Toggle Plain Text)
$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.
Last edited by bad_dreams99 : Apr 22nd, 2008 at 1:13 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Photoshop web photo gallery to dreamweaver (Site Layout and Usability)
- Splitting the Cost of a Photo Gallery Site (Existing Scripts)
- Photo Gallery. (PHP)
- ecommerce online photo gallery (eCommerce)
- php photo gallery extra code needed (PHP)
- Photo Gallery Control (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: ob_start()
- Next Thread: errors since upgrade to php 5.2


Linear Mode