Php Mysql Image Question

Reply

Join Date: Mar 2006
Posts: 52
Reputation: puddin is an unknown quantity at this point 
Solved Threads: 0
puddin puddin is offline Offline
Junior Poster in Training

Php Mysql Image Question

 
0
  #1
May 7th, 2006
Hello.

I have an image system kinda working, when it uploads however it is uoloading calling all the images ARRAY.gif or ARRAY.jpg

Can you see what I should do that it correctly list the images name. The code is two parts. The preupload form page NEXT To The photos.php page where you see your image...

Thanks kindly any help is appreciated!

------------------------------
This is the preupload.php page
-------------------------------


<?php
include 'db.php';

// initialization
$photo_upload_fields = "";
$counter = 1;

// default number of fields
$number_of_fields = 4;

// If you want more fields, then the call to this page should be like,
// preuploads.php?number_of_fields=20

if( $_GET['number_of_fields'] )
$number_of_fields = (int)($_GET['number_of_fields']);

if( $_GET['category_name'] )
$category_name =($_GET['category_name']);

if( $_GET['name'] )
$name =($_GET['name']);


// 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[5]</option>\n


__HTML_END;
}
mysql_free_result( $result );

// Lets build the Photo Uploading fields
while( $counter <= $number_of_fields )
{
$photo_upload_fields.=<<<__HTML_END
<tr>
<td>
Photo {$counter}:
<input name='photo_filename[]' type='file' />
</td>
</tr>
<tr>
<td>
Caption:
<textarea name='name[]' cols='80' rows='1'></textarea>
</td>
</tr>
__HTML_END;
$counter++;
}

// Final Output
echo <<<__HTML_END
<html>
<head>
<title>Lets upload Photos</title>
</head>
<body>
<form enctype='multipart/form-data' action='photos.php' method='post' name='upload_form'>
<table width='90%' border='0' align='center' style='width: 90%;'>
<tr>
<td>
Select Category
<select name='category'>
$photo_category
<option>Woman
<option>Man
</select>
</td>
</tr>

<tr>
<td>
<p>&nbsp;</p>
</td>
</tr>

<!-Insert the photo fields here -->
$photo_upload_fields
<tr>
<td>
<input type='submit' name='submit' value='Add Photos' />
</td>
</tr>
</table>
</form>
</body>
</html>
__HTML_END;
?>




------------------------------------------------------------------------
Next to the photos.php page where the images are seen
------------------------------------------------------------------------
<?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 preupload.php
$photos_uploaded = $_FILES['photo_filename'];

// Fetch the photo caption array
$name = $_POST['name'];

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)."', name='".($name)."' WHERE
email_address='".($email_address)."'" );

$filetype = $photos_uploaded['type'][$counter];
$extention = $known_photo_types[$filetype];
$filename = $name.".".$extention;



$sql_update = mysql_query("UPDATE gallery_photos SET
photo_filename='".($filename)."', name='".($name)."' WHERE
email_address='".($email_address)."'" );

$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."/".$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."/".$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."/tb_".$filename );
ImageDestroy($destination_handle );


$result_final .= "<img src='".$images_dir. "/tb_".$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>
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 50
Reputation: barnamos is an unknown quantity at this point 
Solved Threads: 0
barnamos's Avatar
barnamos barnamos is offline Offline
Junior Poster in Training

Re: Php Mysql Image Question

 
0
  #2
May 8th, 2006
You are using name[] as the variable name. Leave those []'s off and use just name. But you probably want to clean up that text field before using it. However, that's for another post.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 52
Reputation: puddin is an unknown quantity at this point 
Solved Threads: 0
puddin puddin is offline Offline
Junior Poster in Training

Re: Php Mysql Image Question

 
0
  #3
May 14th, 2006
Thank-you kindly Barnamos,

I figured out with "Your reply" to get the picture name in the name field... I am trying to clean up the text field so it will list a second and if I want to allow a third picture , I actually want to allow 4.

I cannot figure it out. It only reads photo_filename as the name, when I try to make the second input pic_filename it doesn't take... Can you maybe tell me how to do this.

Thank-you again you have helped me as lot. I spend hours and I am in school having to study French.... ohhh it's tuff!

THIS IS WHAT I HAVE NOW:


--------------------------
THE PREUPLOAD PAGE
---------------------------

<?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 )
{
$photo_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="upload_form" 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="pic_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;
?>



-----------------------------
THE PICTURE VIEW PAGE:
------------------------------
<?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 preupload.php
$photos_uploaded = $_FILES['photo_filename'];
$photos_uploaded = $_FILES['pic_filename'];



// Fetch the photo caption array
$_POST['name']['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)."', pic_filename='".($filename)."', name='".($name)."' 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)."', pic_filename='".($filename)."', name='".($name)."' 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>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC