Click to See Complete Forum and Search --> : upload thumbnail
zuzupus
08-26-2003, 03:25 AM
hi,
im new bie in PHP i got problem regarding uploading thumbnails from any location or if i just copy the image name in the below text field let say egg.gif it will upload the thumbnail is it possible or everytime i have to click on browse to get the complete location to get the thumbnail.
anybody please help to write the code for me so that when i sumbit the form i can get thumbnails in same page as well as when i add 2nd,3rd and so on it will add one another in same page like
3.egg.gif
2.flower.gif
1.bus.gif and so on
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="tree" value="<?=$tree ?>" />
<table border="0" cellpadding="0" cellspacing="5">
<tr>
<td> </td> -->
<td align="right"><input type="file" name="file" /></td>
<td colspan="5" align="center">
<br /><input class="biggray" type="submit" name="submit" value="TRANSFER" />
</td>
</tr>
</table><br />
</form>
Yes, the users will have to browser to the image each time they want to upload anything. As far as displaying the images, take a look at http://forums.webdeveloper.com/showthread.php?s=&threadid=15902#post83584
zuzupus
08-26-2003, 08:44 AM
thanks alot for your sincere advice so i modified the code in thsi fashion and when i tried to submit the form then system goes crazy felt like drunk :) the process becomes so slow that it eats uo lot of memories as well as it throw one window by saying you need virtual memory :)
<?PHP
$folder = "../assets/upload/";
$handle = opendir($folder);
# Making an array containing the files in the current directory:
while ($file = readdir($handle))
{
$files[] = $file;
}
closedir($handle);
#loop through the files, and only take files that are images.
foreach ($files as $file) {
$f_name = $file;
$fileextention = split ('[.]', $f_name);
$fileext = $fileextention[count($fileextention)-1];
if($fileext=="gif" or $fileext=="png" or $fileext=="bmp" or $fileext=="jpg" or $fileext=="jpeg" or $fileext=="jpe" or $fileext=="tif" or $fileext=="tiff") {
$filename[] = $file;
}
}
#echo out the images...
echo "<table style=\"width: 100%;\">\n\t
\t<tr>\n\t\t<td>Images</td>";
for ($i = 0; $i < count($filename); $i++) {
if ($i % 3 == 0) {
echo "\n\t</tr>\n\t<tr>\n";
}
echo "\t\t<td style=\"width: 33%; border: gray 1px solid; padding: 3px;\"><img src=\"".$folder.$filename[$i]."\" alt=\"Gallery Image\"\"></img><td>\n";
}
echo"\n\t</tr>
</table>\n";
?>
<table border="0" width="500" cellspacing="0" cellpadding="0">
<form action="<?=$HTTP_SERVER_VARS['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<tr>
<td width="130" height="20" align="left" valign="top"><font color="#000000" face="verdana" size="1">Image To Upload :</font><br></td>
<td width="370" height="40" align="left" valign="top"><input type="file" size="40" name="file"></td>
</tr>
<tr>
<td colspan="2" height="20" width="500" align="center" valign="top"><input type="submit" name="upload" value="Upload"></td>
</tr>
</form>
</table>
and how i can get image which can be the size of 170*119pixel
thanks in advance
To upload the images, take a look at http://forums.webdeveloper.com/showthread.php?s=&threadid=10236&highlight=upload and to modify them to what you need, take a look at http://us4.php.net/gd
zuzupus
08-27-2003, 08:12 AM
sorry Pyro for late reply as im using older version of PHP 4.0.6
as i dont ahve any rights to update it moreover its on remote server and GD library:------- GD Support enabled and
GD Version 1.2
i can explain you once again whats the problem actually there is path in server ../assets/upload and here everyday all thumbnails is stored and clients have rights to upload all these thumbnails to his machine for that when he uplaod and submit the form he can see thumbnails and when i try below code it works for all functions like it checks whether file is more and file exits or not but never tells that it uploaded sucessfully,but i will be very glad if you modify htis code so that it can print all thumbnails in order from altest to older thumbnails
<?php
$maxsize = "16384";
$maxwidth = "200";
if(isset($HTTP_POST_VARS['upload'])){
if (!empty($HTTP_POST_FILES['file']['name'])){
$nama=$HTTP_POST_FILES['file']['tmp_name'];
$allowed = array(".jpg"=>"2",".jpeg"=>"2");
$size = getImageSize($nama);
$imgtype = $size[2];
if(!in_array($imgtype,$allowed)) {
echo "<font face=\"verdana\" size=\"2\" color=\"#000000\"><b>Sorry! File Format Not Allowed!</b></font><br>";
exit();
}
$files = $HTTP_POST_FILES['file']['size'];
if($files > $maxsize){
echo "<font face=\"verdana\" size=\"1\" color=\"#000000\">Exceeded maximum file size</font><br>\n";
echo "<font face=\"verdana\" size=\"1\" color=\"#000000\">Maximum File Size is ". round(($maxsize/1024), 2) . "kb</font><br>\n";
echo "<font face=\"verdana\" size=\"1\" color=\"#000000\">Your File Size is ". round(($files/1024), 2) . "kb</font><br><br>\n";
exit();
}
$fol = "../assets/upload/".$HTTP_POST_FILES['file']['name'];
echo $fol;
if(file_exists($fol)) {
die ("<font face=\"verdana\" size=\"1\" color=\"#000000\">File name exist !!</font>");
}
else {
copy($_FILES['file']['tmp_name'], "../assets/upload/" . $HTTP_POST_FILES['file']['name']);
unlink($HTTP_POST_FILES['file']['tmp_name']);
$oripic= "upload/".$_FILES['file']['name'];
$size = getImageSize($oripic);
$imgwidth = $size[0];
$imgheight = $size[1];
$ratio = $imgwidth / $imgheight;
$nratio = $maxwidth / $ratio;
$newheight = $nratio;
if($imgwidth > $maxwidth){
$quality = 85;
$thumb = ImageCreateTrueColor ($maxwidth, $newheight);
$image = ImageCreateFromJpeg($oripic);
imagecopyresized ($thumb, $image, 0, 0, 0, 0, $maxwidth, $newheight, $imgwidth, $imgheight);
imagejpeg($thumb, $oripic, $quality);
imagedestroy($thumb);
}
echo "<font face=\"verdana\" size=\"2\" color=\"#000000\"><b>File Uploaded Successfully</b></font><br><br>";
}
}
else {
echo "<font face=\"verdana\" size=\"2\" color=\"#000000\"><b>You must specify a file to upload</b></font><br>\n";
echo "<font face=\"verdana\" size=\"2\" color=\"#000000\"><a href=\"java script:history.back()\">< < back</a></font><br>\n";
exit();
}
}
?>
<table border="0" width="500" cellspacing="0" cellpadding="0">
<form action="<?=$HTTP_SERVER_VARS['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<tr>
<td width="130" height="20" align="left" valign="top"><font color="#000000" face="verdana" size="1">Image To Upload :</font><br></td>
<td width="370" height="40" align="left" valign="top"><input type="file" size="40" name="file"></td>
</tr>
<tr>
<td colspan="2" height="20" width="500" align="center" valign="top"><input type="submit" name="upload" value="Upload"></td>
</tr>
</form>
</table>
</body>
</html>