therio7 Posted November 13, 2009 Share Posted November 13, 2009 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 : e17fc9a207.jpg in my picture folder when I hit the form upload button. What I need now is a script that will take the picture e17fc9a207.jpg, resize it 100x100, move it to a thumbnail folder and rename it to te same name but with a _t at the end ( i.e: e17fc9a207_t.jpg ) Anyone can help me? I kind of new with php,mysql. My php code is: <?php // 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 "<br>File $fileName uploaded<br>"; 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><br></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><br> </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><br> <br><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 Quote Link to comment https://forums.phpfreaks.com/topic/181393-solved-help-with-image-duplicate-in-php/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.