Perfidus Posted January 17, 2008 Share Posted January 17, 2008 I'm trying to upload, resize and create a thumbnail for a picture, at the same time, I introduce some info about it in a database. The problem is that nothing happens when I execute the form, not even an error message. Any hints? <? $msg = ""; switch(!strcasecmp($_SERVER['REQUEST_METHOD'], "POST")) { case true: if(!isset($_FILES['image']) || $_FILES['image'] == "none" || $_FILES['image'] == "") { $msg = "<span class=\"Estyle3\">Select a picture from your PC</span>"; break; } $conn = mysql_connect("","",""); mysql_select_db("",$conn); $sql = "INSERT INTO pictures (desc, refoto) "; $sql .= "VALUES ('$desc', '$refoto')"; $result = mysql_query($sql) or die(mysql_errno().'<p>'.$sql.'</p>'.mysql_error()); $tmp = getcwd()."/".$_FILES['image']['name']; if(!@move_uploaded_file($_FILES['image']['tmp_name'], $tmp)) { $msg = "<span class=\"Style3\">There was a problem uploading your picture</span>"; break; } $fp = fopen($tmp, "rb"); $str = fread($fp, filesize($tmp)); fclose($fp); unlink($tmp); $im1 = ImageCreateFromString($str); $imgname = $refoto."thumb_1"; $maxwidth = 300; $maxheight = 150; $width1 = ImageSX($im1); $height1 = ImageSY($im1); $width2 = $maxwidth; $height2 = floor(($width2 * $height1) / $width1); if($maxheight > 0 && $height2 > $maxheight) { $height2 = $maxheight; $width2 = floor(($height2 * $width1) / $height1); } $im2 = ImageCreateTrueColor($width2, $height2); ImageCopyResampled($im2, $im1, 0, 0, 0, 0, $width2, $height2, $width1, $height1); ImageJpeg($im2, "fotos/thumb/".$imgname.".jpg"); $msg = "Ok"; $im3 = ImageCreateFromString($str); $imgname2 = $refoto."_1"; $maxwidth2 = 800; $maxheight2 = 250; $width12 = ImageSX($im3); $height12 = ImageSY($im3); $width22 = $maxwidth2; $height22 = floor(($width22 * $height12) / $width12); if($maxheight2 > 0 && $height22 > $maxheight2) { $height22 = $maxheight2; $width22 = floor(($height22 * $width12) / $height12); } $im4 = ImageCreateTrueColor($width22, $height22); ImageCopyResampled($im4, $im3, 0, 0, 0, 0, $width22, $height22, $width12, $height12); ImageJpeg($im4, "fotos/full/".$imgname2.".jpg"); break; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Documento sin título</title> <link rel=stylesheet href="thestyle.css" type="text/css"> </head> <body> <form id="form1" name="form1" method="post"> <input type="file" name="image" size="20"> <input type="hidden" name="value" value="a"> <input type="hidden" name="refoto" value="b45546"> <br /> Picture description(20 caracteres) <br /> <label> <input name="desc" type="text" id="desc" size="20" maxlength="20" /> </label> <label> <input type="submit" name="Submit" value="SEND" /> </label> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/86439-problem-uploading-picture/ Share on other sites More sharing options...
adam291086 Posted January 17, 2008 Share Posted January 17, 2008 When you setup the form creditias you should have something like this. Yours has no action or enctype. Therefore how is the form supposed to know where to send the results? <form action="uploader.php" method="post" enctype="multipart/form-data"> Quote Link to comment https://forums.phpfreaks.com/topic/86439-problem-uploading-picture/#findComment-441721 Share on other sites More sharing options...
Perfidus Posted January 17, 2008 Author Share Posted January 17, 2008 Normally you need to set the "action" for the form, but when it referres to itself it will work without it, if I put the action content it wont work neither... Quote Link to comment https://forums.phpfreaks.com/topic/86439-problem-uploading-picture/#findComment-441725 Share on other sites More sharing options...
adam291086 Posted January 17, 2008 Share Posted January 17, 2008 OK, didn't realsie that about the action. But you have to include the enctype="multipart/form-data" part. As it tell the form you are unloading a file. also put error_reporting(E_ALL); at the top of your code. This will throw out all errors. Quote Link to comment https://forums.phpfreaks.com/topic/86439-problem-uploading-picture/#findComment-441727 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.