Hy, so i found a new thumbnail creator script thanks to kmap, but now i don't know how to make it work with my HTML form. So here it is: I have a page with an HTML form on it, it has some fields like Name, Adress, Age, Email, and i also have an Image field, an optional field where users cand specifi an image.When the Submit button is pressed a process.php page is called wich contain a script, that creates a thumbnail for that specified image, move both source image and thumbnail image to a folder named lets say pics, and after that it inserts into my MySQL DB the data, thats Name, Email, Adress, Age and the 2 images links, the link to the source image and the link to the thumb image.Now the problem is that with this new script i found, wich is very cool, i have no idea how can i make the above process work.Also as i said the image field is optional, so if the user does not specifi and image, the script must ignore the thumbnail creation part of the script and only inserts into the DB the data sent by the Html form. This is what i have done so far, but it doesnt work. this is the page called when the Submit button on the HTML form is pressed. : <?php $con = mysql_connect("*******","*******","*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("******", $con); if(isset($_FILES['image'])){ /** * Create a thumbnail image from $inputFileName no taller or wider than * $maxSize. Returns the new image resource or false on error. * Author: mthorn.net */ $inputFileName = $_FILES['image']; function thumbnail($inputFileName, $maxSize = 80) { $info = getimagesize($inputFileName); $type = isset($info['type']) ? $info['type'] : $info[2]; // Check support of file type if ( !(imagetypes() & $type) ) { // Server does not support file type return false; } $width = isset($info['width']) ? $info['width'] : $info[0]; $height = isset($info['height']) ? $info['height'] : $info[1]; // Calculate aspect ratio $wRatio = $maxSize / $width; $hRatio = $maxSize / $height; // Using imagecreatefromstring will automatically detect the file type $sourceImage = imagecreatefromstring(file_get_contents($inputFileName)); // Calculate a proportional width and height no larger than the max size. if ( ($width <= $maxSize) && ($height <= $maxSize) ) { // Input is smaller than thumbnail, do nothing return $sourceImage; } elseif ( ($wRatio * $height) < $maxSize ) { // Image is horizontal $tHeight = ceil($wRatio * $height); $tWidth = $maxSize; } else { // Image is vertical $tWidth = ceil($hRatio * $width); $tHeight = $maxSize; } $thumb = imagecreatetruecolor($tWidth, $tHeight); if ( $sourceImage === false ) { // Could not load image return false; } // Copy resampled makes a smooth thumbnail imagecopyresampled($thumb, $sourceImage, 0, 0, 0, 0, $tWidth, $tHeight, $width, $height); imagedestroy($sourceImage); return $thumb; } /** * Save the image to a file. Type is determined from the extension. * $quality is only used for jpegs. * Author: mthorn.net */ function imageToFile($im, $fileName, $quality = 80) { if ( !$im || file_exists($fileName) ) { return false; } $ext = strtolower(substr($fileName, strrpos($fileName, '.'))); switch ( $ext ) { case '.gif': imagegif($im, $fileName); break; case '.jpg': case '.jpeg': imagejpeg($im, $fileName, $quality); break; case '.png': imagepng($im, $fileName); break; case '.bmp': imagewbmp($im, $fileName); break; default: return false; } return true; } $im = thumbnail('temp.jpg', 80); imageToFile($im, 'temp-thumbnail.jpg'); $sql = "INSERT INTO anunturi (nume, vanzator, pret, categorie, detalii, telefon, ym, email, parola, imagine, thumbnail) VALUES ('{$_POST['nume']}', '{$_POST['vanzator']}', '{$_POST['pret']}', '{$_POST['categorie']}', '{$_POST['detalii']}', '{$_POST['parola']}', '{$_POST['telefon']}', '{$_POST['ym']}', '{$_POST['email']}', '$sourceimage', '$thumb')"; } else { $sql = "INSERT INTO anunturi (nume, vanzator, pret, categorie, detalii, telefon, ym, email, parola) VALUES ('{$_POST['nume']}', '{$_POST['vanzator']}', '{$_POST['pret']}', '{$_POST['categorie']}', '{$_POST['detalii']}', '{$_POST['parola']}', '{$_POST['telefon']}', '{$_POST['ym']}', '{$_POST['email']}')"; } if(!mysql_query($sql)) echo $sql.'<br>'.mysql_error(); else{ ?> <script> window.location="adaugat.htm" </script> <? mysql_close($con); } ?> Code (markup):
Well, first thing that caught my eye was $inputFileName = $_FILES['image']; and then you send the $inputFileName to the function. $_FILES['image'] is an array and therefore the function getimagesize is getting the wrong parameter. You should be doing $inputFileName = $_FILES['image']['tmp_name']; Or you should save the file first and then give the function direct link to file. Test this and tell us what does the script say..
It gives me Warning: getimagesize(temp.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/content/r/o/b/robertino/html/trimite.php on line 20 Query was empty
The file isn't being saved. I don't know what OS you are running this script at but at *nix usually this temporary file looks like /tmp/ahfkjdhfkh You should check why it isn't being saved properly. This temp.jpg smells fishy. Another option is to use move_uplaoded_file($_FILES['image']['tmp_name'],'temporary.jpg'); and then use $inputFileName='temporary.jpg' but this also won't work if the file isn't being saved properly.
it is Unix, Godaddy Premium account, but there is a problem, if you look at the thumbnail creating script it supports multiple formats so using a temporary.jpg it not good i think, and also check this out, this is an old script i have used before, it worked but its very simple and unadvanced, buggy etc, thats why i want to use the above thumbnail creating script, and i think we can use it for some ideeas on how to make the new one work. here is the old script <?php $con = mysql_connect("*********","********","*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("*********", $con); if(isset($_POST['Submit'])){ $thumbsize = 90; // dimensiunea thumbnail-ului $filedir = 'pics/'; // directorul imaginii pe care o vei uploada $thumbdir = 'pics/'; // directorul imaginii thumbnail $prefix = 'small_'; // prefixul adaugat imaginii $width = 90; $height = 90; $maxfile = '2000000'; $mode = '0666'; $userfile_name = $_FILES['image']['name']; $userfile_tmp = $_FILES['image']['tmp_name']; $userfile_size = $_FILES['image']['size']; $userfile_type = $_FILES['image']['type']; if (isset($_FILES['image']['name'])){ $prod_img = $filedir.$userfile_name; $prod_img_thumb = $thumbdir.$prefix.$userfile_name; move_uploaded_file($userfile_tmp, $prod_img); chmod ($prod_img, octdec($mode)); // Get new dimensions list($width_orig, $height_orig) = getimagesize($prod_img); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } $destimg=ImageCreateTrueColor($thumbsize, $thumbsize) or die('Problem In Creeare thumbnail'); $srcimg=ImageCreateFromJPEG($prod_img) or die('Problem la deschiderea imaginii sursa'); ImageJPEG($destimg, null, 93) or die('Problema la salvare'); ImageCopyResampled($destimg,$srcimg,-($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig) or die('Problem In resizing'); imagedestroy($destimg); $sql = "INSERT INTO anunturi (nume, vanzator, pret, categorie, detalii, telefon, ym, email, parola, imagine, thumbnail) VALUES ('{$_POST['nume']}', '{$_POST['vanzator']}', '{$_POST['pret']}', '{$_POST['categorie']}', '{$_POST['detalii']}', '{$_POST['parola']}', '{$_POST['telefon']}', '{$_POST['ym']}', '{$_POST['email']}', '$prod_img', '$prod_img_thumb')"; } else { $sql = "INSERT INTO anunturi (nume, vanzator, pret, categorie, detalii, telefon, ym, email, parola, imagine, thumbnail) VALUES ('{$_POST['nume']}', '{$_POST['vanzator']}', '{$_POST['pret']}', '{$_POST['categorie']}', '{$_POST['detalii']}', '{$_POST['parola']}', '{$_POST['telefon']}', '{$_POST['ym']}', '{$_POST['email']}')"; } if(!mysql_query($sql)) echo $sql.'<br>'.mysql_error(); else{ ?> <script> window.location="adaugat.htm" </script> <? mysql_close($con); } } ?> Code (markup):
so ? what is to be done ? srry for kepp asking but im stuck with my website development due to this script problem.
W3Schools dot com is in my bookmarks list, trust me, but i dont find anything that cand directly help me in my problem
http us3.php.net/features.file-upload Check out this link. It has a lot of great information regarding file uploads. You might even learn a few new goodies! Sorry the link is not in the correct format, this site does not let "peons" post links. "peon", wow that is pretty degrading.