phpbeginner Posted April 17, 2007 Share Posted April 17, 2007 I have a form and the action goes to a commit page to update my db. I am storing basic info an also image names which works fine. I am trying to resize the images upon upload and my question is can I add in the resize code on the form or do I have to add this on the commit page ? I've tried both but to no avail, so I will concentrate on for or commit page if I knew which one. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted April 17, 2007 Author Share Posted April 17, 2007 Please excuse my ignorance in this matter but I am trying ??? Okay what I have is a form, on save it goes to commit page to save my data, including filename for an image. All works fine so far. Now to actually upload and resize the image using my form can I use the include script (posted below) within my form to upload this image ? If so, do I just have to include this in the head of my page or within the form itself. Any help would be appreciated. <?php if(isset($_POST['Save'])) { $size = 150; // the thumbnail height $filedir = 'test/'; // the directory for the original image $thumbdir = 'test/'; // the directory for the thumbnail image $prefix = ''; // the prefix to be added to the original name $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)); $sizes = getimagesize($prod_img); //$aspect_ratio = $sizes[1]/$sizes[0]; //if ($sizes[1] <= $size) { $new_width = 150; $new_height = 150; //}//else{ //$new_height = $size; //$new_width = abs($new_height/$aspect_ratio); //} $destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image'); $srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image'); } if(function_exists('imagecopyresampled')) { imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); }else{ Imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); } ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving'); imagedestroy($destimg); } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted April 17, 2007 Share Posted April 17, 2007 This needs to go in the file your forms action points to. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted April 17, 2007 Author Share Posted April 17, 2007 Thanks thorpe ! Can I put an include in the file that my form action points to or do I need to use the code itself ? Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 17, 2007 Share Posted April 17, 2007 You can either use a function or the include. Either way you would still have to called one or the other, but it is easy to maintain because if you have a erro or need to update you know where to make corrections. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted April 17, 2007 Author Share Posted April 17, 2007 Okay, this is what I have added to my action page..... if (is_uploaded_file ($flFile)) include('upload.php'); { On my resize include script (upload.php), I would not think I would need any of this if(isset($_POST['Submit'])) as it has already been submitted and gone to an action script......Am I right on this or wrong ? SO here is the upload.php which still is not uploading the files to the directory. <?php { $size = 150; // the thumbnail height $filedir = 'teampics/thumbs'; // the directory for the original image $thumbdir = 'teampics/'; // the directory for the thumbnail image $prefix = ''; // the prefix to be added to the original name $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)); $sizes = getimagesize($prod_img); //$aspect_ratio = $sizes[1]/$sizes[0]; //if ($sizes[1] <= $size) { $new_width = 150; $new_height = 150; //}//else{ //$new_height = $size; //$new_width = abs($new_height/$aspect_ratio); //} $destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image'); $srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image'); } if(function_exists('imagecopyresampled')) { imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); }else{ Imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); } ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving'); imagedestroy($destimg); } } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted April 17, 2007 Share Posted April 17, 2007 Am I right on this or wrong ? Nope, your wrong. The if statement ensures that your script will not run unless the form has been submitted to it. Thus avoiding all sorts of errors if some happens to request this page without submitting the required form. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted April 17, 2007 Author Share Posted April 17, 2007 Added the if(isset($_POST['Submit'])) to my include file as suggested but still no go. This part look OK ? if (is_uploaded_file ($flFile)) include('upload.php'); { which goes into my results.... Quote Link to comment Share on other sites More sharing options...
trq Posted April 17, 2007 Share Posted April 17, 2007 but still no go. Thats far too vague. What is happening? Whats not happening? Maybe you should post both your form and your action scripts. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted April 18, 2007 Author Share Posted April 18, 2007 The filename is being uploaded to DB. The file itself is not uploading. Here is what I have as far as a form I have a form which I can both edit by selecting a record or add a new record. Here is form for adding a new record...... <form name='editDeleteSave' action='commit.php' method='post' enctype='multipart/form-data'> <table> <tr> <p>Upload Image:</p> </td> <td> <input type='file' value='<?php echo($rowPhotos[2]); ?>' name='flFile'><?php echo($rowPhotos[2]); ?> </td> </tr> <tr> <td><input type='hidden' value='' name='saveDelete'> <input type='hidden' value='photos' name='page'> <input type='hidden' value=<?php echo($numPhotos); ?> name='numPhotos'></td> </tr> <?php if($numPhotos!=-1) { echo("<tr><td colspan='2' align='center'><input type='button' name='edit' value='Save Changes' onClick=\"saveChanges('edit');\"><input type='button' name='delete' value='Delete' onClick=\"saveChanges('delete');\"></td></tr>"); } else { echo("<tr><td colspan='2' align='center'><input type='button' name='save' value=' Save ' onClick=\"saveChanges('save');\"></td></tr>"); } ?> Here is the action script for that area.... if($page=='photos') { if($saveDel=='delete') { $rsFileName=mysql_query("select uploadedfile from tblphotos where id=" . $numPhotos); if(mysql_num_rows($rsFileName)!=0) { $rowFileName=mysql_fetch_row($rsFileName); } $result=mysql_query("delete from tblphotos where id=" . $numPhotos); } elseif($saveDel=='edit') { if (is_uploaded_file ($flFile)) include('uploadpic.php'); { $result=mysql_query("update tblphotos set team='" . $txtTeam . "', uploadedfile='" . $flFile_name . "', title='" . $txtTitle . "', description='" . $txtDescription . "' where id=" . $numPhotos); } } else { $result=mysql_query("insert into tblphotos(team,uploadedfile,title,description) values('" . $txtTeam . "','" . $flFile_name . "','" . $txtTitle . "','" . $txtDescription . "')"); } echo("<script language='javascript'>location.href='jhfksa.php'</script>"); and the include script..... <?php if(isset($_POST['Submit'])) { $size = 150; // the thumbnail height $filedir = 'test/'; // the directory for the original image $thumbdir = 'test/'; // the directory for the thumbnail image $prefix = ''; // the prefix to be added to the original name $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)); $sizes = getimagesize($prod_img); //$aspect_ratio = $sizes[1]/$sizes[0]; //if ($sizes[1] <= $size) { $new_width = 150; $new_height = 150; //}//else{ //$new_height = $size; //$new_width = abs($new_height/$aspect_ratio); //} $destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image'); $srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image'); } if(function_exists('imagecopyresampled')) { imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); }else{ Imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); } ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving'); imagedestroy($destimg); } ?> On the include script I have tried submit, edit and save......I appreciate the help thorpe ! Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted April 18, 2007 Author Share Posted April 18, 2007 any suggestions on this.....I posted what I have. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted April 18, 2007 Author Share Posted April 18, 2007 Can someone assist me with this ? I really, really, really hate the thoughts of storing my images in database but may have to if I can't get this working. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted April 18, 2007 Author Share Posted April 18, 2007 quietly bumping....and for info, the filename is saving to the db, but the images are not uploading. Quote Link to comment 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.