Script200 Posted August 8, 2010 Share Posted August 8, 2010 I need help modifying this script. I wanna add a "File Size" to it. So it will check file sized and set a maximum. Thanks. <?php //Windows way $uploadLocation = "C:\\www\\upload\\"; //Unix, Linux way //$uploadLocation = "\tmp"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>X-NET File Uploader</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div id="caption">UPLOAD FILE</div> <div id="icon"> </div> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" id="fileForm" enctype="multipart/form-data"> File to upload:<center> <table> <tr><td><input name="upfile" type="file" size="36"></td></tr> <tr><td align="center"><br/><input class="text" type="submit" name="submitBtn" value="Upload"></td></tr> </table></center> </form> <?php if (isset($_POST['submitBtn'])){ ?> <div id="caption">RESULT</div> <div id="icon2"> </div> <div id="result"> <table width="100%"> <?php $target_path = $uploadLocation . basename( $_FILES['upfile']['name']); if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) { echo "The file: ". basename( $_FILES['upfile']['name']). " has been uploaded!"; } else{ echo "There was an error uploading the file, please try again!"; } ?> </table> </div> <?php } ?> <div> </body> Link to comment https://forums.phpfreaks.com/topic/210116-need-help-modifying-a-script/ Share on other sites More sharing options...
Yesideez Posted August 8, 2010 Share Posted August 8, 2010 First, check this out: http://php.net/manual/en/function.filesize.php I think you need to use that on $target_path at some point, maybe when letting the user know the file has been uploaded? Link to comment https://forums.phpfreaks.com/topic/210116-need-help-modifying-a-script/#findComment-1096557 Share on other sites More sharing options...
Script200 Posted August 8, 2010 Author Share Posted August 8, 2010 So something in the likes off: echo $_FILES . ': ' . filesize($_FILES) . ' bytes'; And than how do I check for a max file size and include that? Link to comment https://forums.phpfreaks.com/topic/210116-need-help-modifying-a-script/#findComment-1096604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.