| | |
Php Mysql Image Question
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.
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> </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>
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> </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>
•
•
Join Date: Mar 2006
Posts: 52
Reputation:
Solved Threads: 0
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>
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>
![]() |
Similar Threads
- PHP and MySQL newbie introducing self (PHP)
- Php Mysql Image Help Please!!! (PHP)
- 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: Music library
- Next Thread: ugh! One Page, 2 re-loads (page request i guess)
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dropdown dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube





