Page is a not externally linkable
Birdman - 10:45 pm on Mar 21, 2003 (gmt 0)
This thread is going in my Bookmarks for sure. Here is my contribution and feel free scrutinize it, as I am sure there are more elegant ways to code some parts. This script works with a MySQL [mysql.com] database that contains info for the pics. You need to create a table named pics. The Form loademup.php <?php $uploaddir = '/home/username/public_html/images/'; if ($_FILES['userfile']['name'][$q] == "") continue; while($i = mysql_fetch_array($result)){ if (move_uploaded_file( [php.net]$_FILES['userfile']['tmp_name'][$q], $uploaddir . $new_pic)) { $new_thumb = "thumbs/$new_pic"; if ($source_x > $source_y){ $targetfile = "$uploaddir$new_thumb"; view.php <?php for ($q=0;$q<$tot;$q++){ [1][edited by: jatar_k at 9:23 pm (utc) on July 21, 2004]
Image upload and Thumbnail Generator
CREATE TABLE `pics` (
`pid_id` VARCHAR NOT NULL ,
`pic_name` VARCHAR( 150 ) ,
`descrip` TEXT,
PRIMARY KEY ( `pid_id` )
)
<form enctype="multipart/form-data" action="loademup.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="300000">
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input type="submit" />
</form>
<html>
<head><title>Enter Name and Descriptions of Pics</title></head>
<body>
<h1>Enter Name and Descriptions of Pics</h1>
<form action="view.php" method="post">
$dbh=mysql_connect( [php.net]"localhost", "username", "password") or die ('I cannot connect to the database.');
mysql_select_db( [php.net]"db");
$tot = count( [php.net]$userfile);
$num = 0;
for($q=0;$q<$tot;$q++){
$num = $num + 1;
$sql = "SELECT pic_id FROM pics ORDER BY pic_id DESC LIMIT 1";
$result = mysql_query( [php.net]$sql);
$new_id = $i['pic_id'] + 1;
$new_pic = "$new_id.jpg";
}
$sql = "INSERT INTO `pics` ( `pic_id` , `name` , `descrip` )VALUES ('$new_id', NULL , NULL);";
mysql_query( [php.net]$sql);
} else {
print "<strong>$_FILES['userfile']['name'][$q]</strong> did not upload!";
}
$sourcefile = "$uploaddir$new_pic";
$picsize = getimagesize( [php.net]"$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize;
$dest_x = 200;
$dest_y = 150;
} else {
$dest_x = 150;
$dest_y = 200;
}
$jpegqual = 75;
$source_id = imagecreatefromjpeg( [php.net]"$sourcefile");
$target_id = imagecreatetruecolor( [php.net]$dest_x, $dest_y);
$target_pic = imagecopyresized( [php.net]$target_id,$source_id,0,0,0,0,$dest_x,$dest_y,$source_x,$source_y);
imagejpeg( [php.net]$target_id,"$targetfile",$jpegqual);
?>
<div style="clear: both;">
<a href="/images/<?=$new_pic?>">
<img src="/images/<?=$new_thumb?>" style="float: left" />
</a>
<strong><?=$_FILES['userfile']['name'][$q]?></strong><br /><br />
<strong>Name:</strong><br />
<input type="text" name="pic_name[<?=$num?>]" /><br /><br />
<strong>Description:</strong><br />
<textarea name="descrip[<?=$num?>]"></textarea>
<input type="hidden" name="pic_id[<?=$num?>]" value="<?=$new_id?>" />
</div>
<?php
}
?>
<input type="submit" value="Click to Save Descriptions" />
</form>
</body>
</html>
<html>
<head><title>View Pics and Descriptions</title></head>
<body>
<h1>View Pics and Descriptions</h1>
$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database.');
mysql_select_db ("db");$num = 0;
$tot = count($pic_id);
$num = $num + 1;
$sql = "UPDATE pics SET descrip = '$descrip' , name = '$pic_name' WHERE pic_id = $pic_id[$num]";
mysql_query($sql);
?>
<div style="clear: both;">
<a href="/images/<?php echo "$pic_id[$num].jpg"?>">
<img src="/images/thumbs/<?php echo "$pic_id[$num].jpg"?>" style="float: left" />
</a>
<h2><?=$pic_name[$num]?></h2>
<p><?=$descrip[$num]?></p>
</div>
<?php
}
mysql_close( [php.net]);
?>
</body>
</html>
[edit reason] small syntax change [/edit]