| | |
php mysql image again PLEASE HELP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2006
Posts: 52
Reputation:
Solved Threads: 0
Hello ,
If you know the answer please simplify it for me. I am so discouraged trying to figure this out. I'll be very grateful, Thanks ahead a time!
When I insert my (2) selected photos in my photo form , they show two pictures but it repeats only (1) of the pictures. it shows up double.
Next it goes to the directory as one image name and type.
Next in the database I have photo1 and photo2 it logs in photo1 and photo2 the same image though,
but in name1 and name2 it logs the name correctly but no type!
For the life of me I cannot get the pictures to show up as the two seperate photos I am inserting, and log in the database as photo1 and photo2 as two seperate photos... They log photo1 and photo2 as the same name and type... CAN you HELP!
Easily I select cat.gif and dog.gif on display only cat.gif displays twice ...
In the directory it logs only once cat.gif ...
In the database it logs repeated cat.gif in photo1 and photo2 ....
In the database under name1 it is logging cat and in name2 it is logging dog correctly but no type!
How can I write it correctly that two photos are being selected and not just one... Here is my code:
____________________
THIS IS THE PHOTO_FORM
-------------------------------
<?php
include 'db.php';
// initialization
$photo_upload;
$counter = 1;
if( $_GET['number_of_fields'] )
$number_of_fields = (int)($_GET['number_of_fields']);
// Firstly Lets build the Category List
$result = mysql_query( "SELECT category_id,category_name FROM gallery_category" );
while( $row = mysql_fetch_array( $result ) )
{
$photo_category_list .=<<<__HTML_END
<option value="$row[0]">$row[1]</option>\n
__HTML_END;
}
mysql_free_result( $result );
// Lets build the Photo Uploading fields
while( $counter <= $number_of_fields )
{
$photos_upload;
__HTML_END;
$counter++;
}
// Final Output
echo <<<__HTML_END
<!-Insert the photo fields here -->
$photo_upload
<html>
<head>
<title>Lets upload Photos</title>
</head>
<body>
<table>
<tr>
<td>
<form name="photo_filename" action="photos.php" method="post" enctype="multipart/form-data">
<p><b>
Photo:
<input name="photo_filename[]" type="file">
Caption: <textarea name='name' cols='20' rows='1'></textarea></p>
<br>
<p>Photo:
<input name="photo_filename[]" type="file">
Caption: <textarea name='name2' cols='20' rows='1'></textarea></p>
<tr>
<td>
<input type='submit' name='submit' value='Add Photos' />
</td>
</tr>
</table>
</form>
</body>
</html>
__HTML_END;
?>
_______________
THIS IS THE DISPLAY
__________________________
<?php
include 'db.php';
// initialization
$result_final = "";
$counter = 0;
// List of our known photo types
$known_photo_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'image/x-png' => 'png'
);
// GD Function List
$gd_function_suffix = array(
'image/pjpeg' => 'JPEG',
'image/jpeg' => 'JPEG',
'image/gif' => 'GIF',
'image/bmp' => 'WBMP',
'image/x-png' => 'PNG'
);
//ignore anything starting with a period.
if(substr($filename, 0, 1)!='.')
// Fetch the photo array sent by preuploads.php
$photos_uploaded = $_FILES['photo_filename'];
// Fetch the photo caption array
$_POST['name'];
$_POST['name2'];
while( $counter <= count($photos_uploaded) )
{
if($photos_uploaded['size'][$counter] > 0)
{
if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
{
$result_final .= "File ".($counter+1)." is not a photo<br />";
}else{
$sql_update = mysql_query("UPDATE gallery_photos SET photo_filename='".($filename)."', photo2_filename='".($filename)."',
name='".($name)."', name2='".($name2)."' WHERE email_address='".($email_address)."' AND password='".($password)."'" );
$filetype = $photos_uploaded['type'][$counter];
$extention = $known_photo_types[$filetype];
$filename = $name.".".$extention;
$sql_update = mysql_query("UPDATE gallery_photos SET photo_filename='".($filename)."', photo2_filename='".($filename)."',
name='".($name)."', name2='".($name2)."' WHERE email_address='".($email_address)."' AND password='".($password)."'" );
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
echo ("");
} else {
echo ("");
}
// Store the orignal file
copy($photos_uploaded['tmp_name'][$counter], $images_dir."/$name_".$filename );
// Let's get the Thumbnail size
$size = GetImageSize( $images_dir."/".$filename );
if($size[0] > $size[1])
{
$thumbnail_width = 100;
$thumbnail_height = (int)(100 * $size[1] / $size[0]);
}
else
{
$thumbnail_width = (int)(100 * $size[0] / $size[1]);
$thumbnail_height = 100;
}
// Build Thumbnail with GD 1.x.x, you can use the other described methods too
$function_suffix = $gd_function_suffix[$filetype];
$function_to_read = "ImageCreateFrom".$function_suffix;
$function_to_write = "Image".$function_suffix;
// Read the source file
$source_handle = $function_to_read ( $images_dir."/$name_".$filename );
if($source_handle)
{
// Let's create an blank image for the thumbnail
$destination_handle = ImageCreate ( $thumbnail_width, $thumbnail_height );
// Now we resize it
ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width,
$thumbnail_height, $size[0], $size[1] );
}
// Let's save the thumbnail
$function_to_write( $destination_handle, $images_dir."/$name_".$filename );
ImageDestroy($destination_handle );
//
$result_final .= "<img src='".$images_dir. "/$name_".$filename."' /> File ".($counter+1)."
Added<br />";
}
}
$counter++;
}
// Print Result
echo <<<__HTML_END
<html>
<head>
<title>Photos uploaded</title>
</head>
<body>
$result_final
</body>
</html>
__HTML_END;
?>
</p>
</table>
</body>
</html>
P.S IF I TRY TO ADD photo2_filename it doesn't work!
Your help will be really appreciated, Thanks Puddin
If you know the answer please simplify it for me. I am so discouraged trying to figure this out. I'll be very grateful, Thanks ahead a time!
When I insert my (2) selected photos in my photo form , they show two pictures but it repeats only (1) of the pictures. it shows up double.
Next it goes to the directory as one image name and type.
Next in the database I have photo1 and photo2 it logs in photo1 and photo2 the same image though,
but in name1 and name2 it logs the name correctly but no type!
For the life of me I cannot get the pictures to show up as the two seperate photos I am inserting, and log in the database as photo1 and photo2 as two seperate photos... They log photo1 and photo2 as the same name and type... CAN you HELP!
Easily I select cat.gif and dog.gif on display only cat.gif displays twice ...
In the directory it logs only once cat.gif ...
In the database it logs repeated cat.gif in photo1 and photo2 ....
In the database under name1 it is logging cat and in name2 it is logging dog correctly but no type!
How can I write it correctly that two photos are being selected and not just one... Here is my code:
____________________
THIS IS THE PHOTO_FORM
-------------------------------
<?php
include 'db.php';
// initialization
$photo_upload;
$counter = 1;
if( $_GET['number_of_fields'] )
$number_of_fields = (int)($_GET['number_of_fields']);
// Firstly Lets build the Category List
$result = mysql_query( "SELECT category_id,category_name FROM gallery_category" );
while( $row = mysql_fetch_array( $result ) )
{
$photo_category_list .=<<<__HTML_END
<option value="$row[0]">$row[1]</option>\n
__HTML_END;
}
mysql_free_result( $result );
// Lets build the Photo Uploading fields
while( $counter <= $number_of_fields )
{
$photos_upload;
__HTML_END;
$counter++;
}
// Final Output
echo <<<__HTML_END
<!-Insert the photo fields here -->
$photo_upload
<html>
<head>
<title>Lets upload Photos</title>
</head>
<body>
<table>
<tr>
<td>
<form name="photo_filename" action="photos.php" method="post" enctype="multipart/form-data">
<p><b>
Photo:
<input name="photo_filename[]" type="file">
Caption: <textarea name='name' cols='20' rows='1'></textarea></p>
<br>
<p>Photo:
<input name="photo_filename[]" type="file">
Caption: <textarea name='name2' cols='20' rows='1'></textarea></p>
<tr>
<td>
<input type='submit' name='submit' value='Add Photos' />
</td>
</tr>
</table>
</form>
</body>
</html>
__HTML_END;
?>
_______________
THIS IS THE DISPLAY
__________________________
<?php
include 'db.php';
// initialization
$result_final = "";
$counter = 0;
// List of our known photo types
$known_photo_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'image/x-png' => 'png'
);
// GD Function List
$gd_function_suffix = array(
'image/pjpeg' => 'JPEG',
'image/jpeg' => 'JPEG',
'image/gif' => 'GIF',
'image/bmp' => 'WBMP',
'image/x-png' => 'PNG'
);
//ignore anything starting with a period.
if(substr($filename, 0, 1)!='.')
// Fetch the photo array sent by preuploads.php
$photos_uploaded = $_FILES['photo_filename'];
// Fetch the photo caption array
$_POST['name'];
$_POST['name2'];
while( $counter <= count($photos_uploaded) )
{
if($photos_uploaded['size'][$counter] > 0)
{
if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
{
$result_final .= "File ".($counter+1)." is not a photo<br />";
}else{
$sql_update = mysql_query("UPDATE gallery_photos SET photo_filename='".($filename)."', photo2_filename='".($filename)."',
name='".($name)."', name2='".($name2)."' WHERE email_address='".($email_address)."' AND password='".($password)."'" );
$filetype = $photos_uploaded['type'][$counter];
$extention = $known_photo_types[$filetype];
$filename = $name.".".$extention;
$sql_update = mysql_query("UPDATE gallery_photos SET photo_filename='".($filename)."', photo2_filename='".($filename)."',
name='".($name)."', name2='".($name2)."' WHERE email_address='".($email_address)."' AND password='".($password)."'" );
$sql_check_num = mysql_num_rows($sql_check);
if($sql_check_num == 0){
echo ("");
} else {
echo ("");
}
// Store the orignal file
copy($photos_uploaded['tmp_name'][$counter], $images_dir."/$name_".$filename );
// Let's get the Thumbnail size
$size = GetImageSize( $images_dir."/".$filename );
if($size[0] > $size[1])
{
$thumbnail_width = 100;
$thumbnail_height = (int)(100 * $size[1] / $size[0]);
}
else
{
$thumbnail_width = (int)(100 * $size[0] / $size[1]);
$thumbnail_height = 100;
}
// Build Thumbnail with GD 1.x.x, you can use the other described methods too
$function_suffix = $gd_function_suffix[$filetype];
$function_to_read = "ImageCreateFrom".$function_suffix;
$function_to_write = "Image".$function_suffix;
// Read the source file
$source_handle = $function_to_read ( $images_dir."/$name_".$filename );
if($source_handle)
{
// Let's create an blank image for the thumbnail
$destination_handle = ImageCreate ( $thumbnail_width, $thumbnail_height );
// Now we resize it
ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width,
$thumbnail_height, $size[0], $size[1] );
}
// Let's save the thumbnail
$function_to_write( $destination_handle, $images_dir."/$name_".$filename );
ImageDestroy($destination_handle );
//
$result_final .= "<img src='".$images_dir. "/$name_".$filename."' /> File ".($counter+1)."
Added<br />";
}
}
$counter++;
}
// Print Result
echo <<<__HTML_END
<html>
<head>
<title>Photos uploaded</title>
</head>
<body>
$result_final
</body>
</html>
__HTML_END;
?>
</p>
</table>
</body>
</html>
P.S IF I TRY TO ADD photo2_filename it doesn't work!
Your help will be really appreciated, Thanks Puddin
I haven't finish all your code but I spot something that is not suitable in HTML - In the PHOTO_FORM, you have photo_filename[] as you input name of the file. As HTML is not like php, it will not take your file data into an array. You may want to change it to photo_filename1 and photo_filename2 for the second image.
Then in your upload script, use $_POST['photo_filename1'] and $_POST['photo_filename2'] to retrive it. If you have to upload many images at once, you can use For loop to remove the need of repeating scripts.
Post your finding here again if it still not working.
Then in your upload script, use $_POST['photo_filename1'] and $_POST['photo_filename2'] to retrive it. If you have to upload many images at once, you can use For loop to remove the need of repeating scripts.
Post your finding here again if it still not working.
Ecommerce-Web-Store.com Building Your e-Business.
•
•
•
•
Originally Posted by zippee
I haven't finish all your code but I spot something that is not suitable in HTML - In the PHOTO_FORM, you have photo_filename[] as you input name of the file.
You can use that in HTML. photo_filename[] is perfectly legal in HTML. It will store all the selected options into an array. There is nothing wrong with that.
![]() |
Similar Threads
- Php Mysql Image Help Please!!! (PHP)
- Php Mysql Image Question (PHP)
- PHP/MySQL programmer looking for project (Post your Resume)
- 5 Years Experiance In the PHP+MYSQL language and DB (Post your Resume)
- PHP/MySQL developer available (Post your Resume)
- Freelance PHP/MySQL Developer available (Post your Resume)
Other Threads in the PHP Forum
- Previous Thread: Payment/Subscription System Freelance Project
- Next Thread: random page crashes in php
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail menu mlm mod_rewrite multiple mysql number oop parse paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space sql structure subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere xml youtube





