View unanswered posts | View active topics It is currently Wed Oct 01, 2014 5:48 am



Reply to topic  [ 1 post ] 
 Automatic Thumbnail code 
Author Message
Junior Member

Joined: Thu Nov 12, 2009 6:04 pm
Posts: 6
Post Automatic Thumbnail code
Hi,

I have a php form where I can upload 3 things into a database.

1. Image Description
2. Image category
3. Image (the image is uploaded in a folder with a unique random name, and the unique path name is inserted into the

database)

My script generate something like : 3a54b42fa7103570ea1729e17fc9a207.jpg
in my picture folder when I hit the form upload button.

What I need now is a thumbnail version of that image created in the same folder but with a different file name and in

smaller size , something like :
3a54b42fa7103570ea1729e17fc9a207_T.jpg

Anyone can help me? I kind of new with php,mysql.

My php code is:

<?

// image directory
$uploadDir = ( $_SERVER['DOCUMENT_ROOT'].'/vitrail_path/photos/' );

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$description = $_POST['description'];
$categorie = $_POST['categorie'];

// get the file extension first
$ext = substr(strrchr($fileName, "."), 1);

// generate the random file name
$randName = md5(rand() * time());

// unique file name for the upload file
$filePath = $uploadDir . $randName . '.' . $ext;

// move the files to the specified directory with error reporting
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}

if (file_exists(( $_SERVER['DOCUMENT_ROOT'].'/vitrail_path/photos/' ) . $_FILES['userfile']['tmp_name']))
{
echo $_FILES['userfile']['tmp_name'] . ' already exists. ';
}

if(!$_POST['description'] | !$_POST['categorie']) {
die('Inscrire une description et une catégorie.');
}

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include 'library/config.php';
include 'library/opendb.php';

$query = "INSERT INTO upload2 (name, size, type, path, description, categorie) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath', '$description', '$categorie')";

mysql_query($query) or die('Error, query failed');

include 'library/closedb.php';

echo "
File $fileName uploaded
";
header('Location: upload.php');
}

?>



And my form code is
<form method="post" enctype="multipart/form-data" name="uploadform">
<h4>
<table border="0" align = "center">
<tr align="left" valign="top"><td>
</td></tr>
<tr align="left" valign="middle" height="10"><td><b><font size="2" face="Georgia, Arial" color="black">Description de

la

photo :</font></b></td><td height="10">
<input type="text" name="description" maxlength="75" size="75">
</td></tr>
<tr align="left" valign="middle"><td><font size="2" face="Georgia, Arial" color="black"><b>Catégorie

:</b></font></td><td>
<select name="categorie">
<option selected>Animaux</option>
<option>Bord de mer</option>
<option>Décorations des fêtes</option>
<option>Divers</option>
<option>Fleurs</option>
<option>Oiseaux</option>
<option>Victorien</option>
</select>
</td></tr>
<tr align="left" valign="middle">
<td> </td>
<td> </td>
</tr>
<tr align="left" valign="middle">
<td><font size="2" face="Georgia, Arial" color="black"><b>Sélection de la photo :</b></font>

</td>
<td><input type="hidden" name="MAX_FILE_SIZE" value="60000000">
<input name="userfile" type="file" id="userfile" size="25"></td>
</tr>
<tr align="left" valign="middle"><td></td>
<td>


<img src="images/transparent.gif" width="363" height="10" border=0><input name="upload" type="submit"

class="box"

id="upload" value=" Ajouter la photo "></td></tr>
</table>
</h4>

</form>


Thanks


Thu Nov 12, 2009 6:08 pm
Report this post
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.