TennesseeGuy Posted March 14, 2006 Share Posted March 14, 2006 Does anyone know of any easy to use upload scripts that allow for two things: 1) Limiting the file size. 2) Limiting the dimensions? I am hoping to integrate an upload feature to a current PhP script I am using but none exists for that particular script so am Googlin as we speak in search of a nice little upload script :)Thanks. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 15, 2006 Share Posted March 15, 2006 The php manual has a pretty indepth look at handling file uploads.[a href=\"http://us3.php.net/manual/en/features.file-upload.php\" target=\"_blank\"]http://us3.php.net/manual/en/features.file-upload.php[/a]It includes limiting the file size.Limiting dimensions can be done using getimagesize (http://www.php.net/getimagesize), which returns, among other things, the height and width of the image. Quote Link to comment Share on other sites More sharing options...
Eugene Posted March 15, 2006 Share Posted March 15, 2006 [a href=\"http://www.tizag.com/phpT/fileupload.php\" target=\"_blank\"]http://www.tizag.com/phpT/fileupload.php[/a] Quote Link to comment Share on other sites More sharing options...
TennesseeGuy Posted March 15, 2006 Author Share Posted March 15, 2006 Thanks you two. Will read up on both links tomorrow. Time to take my old bones to bed so I can give my old brain a break before dig into some php readings :) Look forward to learning something new tomorrow :) Thanks again! Quote Link to comment Share on other sites More sharing options...
TennesseeGuy Posted March 15, 2006 Author Share Posted March 15, 2006 [!--quoteo(post=355191:date=Mar 14 2006, 09:37 PM:name=G F D)--][div class=\'quotetop\']QUOTE(G F D @ Mar 14 2006, 09:37 PM) [snapback]355191[/snapback][/div][div class=\'quotemain\'][!--quotec--][a href=\"http://www.tizag.com/phpT/fileupload.php\" target=\"_blank\"]http://www.tizag.com/phpT/fileupload.php[/a][/quote]Nice small toot but doesn't exactly assist with my exact needs but a good beginner tut for learning about file upload :)[!--quoteo(post=355183:date=Mar 14 2006, 09:16 PM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Mar 14 2006, 09:16 PM) [snapback]355183[/snapback][/div][div class=\'quotemain\'][!--quotec--]The php manual has a pretty indepth look at handling file uploads.[a href=\"http://us3.php.net/manual/en/features.file-upload.php\" target=\"_blank\"]http://us3.php.net/manual/en/features.file-upload.php[/a][/quote]From a quick 5 minute glance this small thread has everything I could ever need to know about writing my own version of file upload so I rekkon I'll spend a few hours reading through this thread and doing some trial and error practice ;) While I am playing with my new little script does anyone know if you can implement a file upload script to an existing form? From a quick glance it appears that the upload scripts are standalone applications but I would like it to play a part of a whole script. When the user submits the form (upload included) all other parts of the form has handled the way they currently are and the only thing that changes is the part regarding the actual uploaded file. Or do you need to upload the file for preview and then redirect back to the original page with the previewed image so the user may continue completion of the form? Thanks for your help....back a reading I a go :) Quote Link to comment Share on other sites More sharing options...
TennesseeGuy Posted March 17, 2006 Author Share Posted March 17, 2006 I have spent about half a day reading through the php manual regarding file upload and enhaned upload features. Have tried to put together a script, use an already developed script, play around with multiple scripts, and still no success. I do not get any errors but nothing gets uploaded. I am thinking that it has something to do with the way the form is being handled and not the actual script itself. Can anyone have a look and let me know what I am doing wrong here?!? thanks.[code]HTML:<form method="post" id="form1" action="<?php echo $editFormAction; ?>" onsubmit="return check_form(form1);"><div id="sponsorDiv" class="pgPictureDiv"><div class="leftColFloat">Test Upload</div><div class="rightColFloat"><input name="file" type="file" value="<?php if ($_POST['file']) echo $_POST['file'];?>" /></div><input type="submit" onclick="MM_validateForm('url','','R','title','','R','keywords','','R','description','','R','linkType','','R','email','','RisEmail');return document.MM_returnValue" value="Submit" />PHP:$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if (($_POST['url'] != '') && ($_POST['url'] != 'http://')) {if ($_POST['file'] != '') { include('include/uploadSponsor.php'); } }}[/code]Essientially what I am gathering from the form it processes quite a variety of fields and if validates moves onthroughout the field. I through this validation piece outside an else so it will atleast always check to see if it is valid. I am attempting to ECHO the file name as the value of the upload and validating that if the value is not null then run my upload script. I am guessing this script is never being ran because I attempted to upload a rather large file and it processed instantaneously. Any ideas anyone? Thanks :) Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 17, 2006 Share Posted March 17, 2006 You are using $_POST['file'] to address the file...you should use the $_FILES array...in your form above you use would $_FILES['file'] then ['size'] for file size, or ['tmpname'] for the temp name, and so on. Quote Link to comment Share on other sites More sharing options...
TennesseeGuy Posted March 17, 2006 Author Share Posted March 17, 2006 The only reason I am using POST rather then FILES is because the existing developed form is already using this particular structure. Should using post to call the actual PhP file void this action? The oinly reason I ask is because I even attempted using a call action if an upload occured for the simplest of scripts and it never processed either:[code]TEST.PHP<?phpvar_dump(gd_info());?>[/code] Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 17, 2006 Share Posted March 17, 2006 You have to access the file through the $_FILES array. You are also missing the enctype in your opening form tag.[code]<?phpini_set("error_reporting", "E_ALL");$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if (isset($_POST) || isset($_FILES)) { echo $_POST['sometext'] . "<br />"; if ($_FILES['file1']['size'] > 0) { echo "file name: " . $_FILES['file1']['name'] . "<br />"; echo "file size: " . $_FILES['file1']['size'] . "<br />"; echo "file type: " . $_FILES['file1']['type'] . "<br />"; }}?><br /><br /><br /><form method="post" enctype="multipart/form-data" action="<?php echo $editFormAction; ?>"> <div id="sponsorDiv" class="pgPictureDiv"> <div class="leftColFloat">Test Upload</div> <div class="rightColFloat"> <input type="text" name="sometext" /><br /> <input name="file1" type="file" /> </div> <input type="submit" value="Submit" /> </div></form>[/code] Quote Link to comment Share on other sites More sharing options...
TennesseeGuy Posted March 17, 2006 Author Share Posted March 17, 2006 It still didn't do anything. Didn't echo anything.....just submitted the file as if it were complete :( Ughhhhhh I have been pullin my greys out just trying to get to a point where I can actually test the script....it keeps gettin skipped :(I also ran a php.ini test just to see if I could see anything wrong but it looks like everything is good to go:display_errors = 1 register_globals = 1 post_max_size = 55M post_max_size+1 = 56 post_max_size in bytes = 57671680 I also ran a gd dump and this is what I got:array(11) { ["GD Version"]=> string(27) "bundled (2.0.28 compatible)" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["T1Lib Support"]=> bool(false) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) } Quote Link to comment Share on other sites More sharing options...
TennesseeGuy Posted March 17, 2006 Author Share Posted March 17, 2006 I just tried another idea and it too failed. I thought I would add a die script but the form still processed and skipped this step entirely:[code]if (isset($_POST) || isset($_FILES)) { echo $_POST['sometext'] . "<br />"; if ($_FILES['file1']['size'] > 0) { echo "file name: " . $_FILES['file1']['name'] . "<br />"; echo "file size: " . $_FILES['file1']['size'] . "<br />"; echo "file type: " . $_FILES['file1']['type'] . "<br />"; }}else { $_POST[die];}[/code] Quote Link to comment Share on other sites More sharing options...
TennesseeGuy Posted March 17, 2006 Author Share Posted March 17, 2006 Am getting really close now....the script pocesses as desired with my condtionals but has one bug in it. Have tried the following to work out the bug but that didn't work. My goal is too not process the upload script if there was no image uploaded (i.e. the end user never clicked browse select image). The bug is the script ptocesses regardless is an image was supplied or not which cause errors in the uplaod script if no script was ever uploaded. Thanks for all your help :) Any ideas?if ((isset($_FILES['sponsorAd'])) && ($_POST['linkType'] == 'sponsor')) {$size = array($_FILES['sponsorAd']['size']);if (sizeof($size) > 0) {include('include/uploadSponsor.php');}} 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.