supanoob Posted September 21, 2007 Share Posted September 21, 2007 Hey, im using an upload script i found and am wanting to mod it to check file type and size. I was wondering if you could tell me how to do this? This is the code i have, and i want it to check make sure the it is a jpeg, jpg or gif and less than 25KB in size. <?php if ($_GET['action'] == 'uploaded') { // Your file name you are uploading $file_name = $HTTP_POST_FILES['ufile']['name']; // random 4 digit to add to our file name // some people use date and time in stead of random digit $random_digit=rand(0000,9999); //combine random digit to you file name to create new file name //use dot (.) to combile these two variables $new_file_name=$random_digit.$file_name; //set where you want to store files //in this example we keep file in folder upload //$new_file_name = new upload file name //for example upload file name cartoon.gif . $path will be upload/cartoon.gif $path= "images/characters/".$new_file_name; if($ufile !=none) { if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { echo "Successful<BR/>"; //$new_file_name = new file name //$HTTP_POST_FILES['ufile']['size'] = file size //$HTTP_POST_FILES['ufile']['type'] = type of file echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; } else { echo "Error"; } } } ?> Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 What version of PHP are you using? Regards Huggie Quote Link to comment Share on other sites More sharing options...
MadTechie Posted September 21, 2007 Share Posted September 21, 2007 thats script looks kinda old but to add filesize check change if($ufile !=none) to if($ufile !=none && $HTTP_POST_FILES['ufile']['size'] < 25000) Quote Link to comment Share on other sites More sharing options...
supanoob Posted September 21, 2007 Author Share Posted September 21, 2007 What version of PHP are you using? Regards Huggie im using PHP version 5.2.3 Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 im using PHP version 5.2.3 In that case you'll want to change each instance of $HTTP_POST_FILES to $_FILES for a start. Then as MadTechie says, you can use $_FILES['ufile']['size'] to get the size. As for how you want to chose the file type, this can be either by extension or mime type. Regards Huggie Quote Link to comment Share on other sites More sharing options...
supanoob Posted September 21, 2007 Author Share Posted September 21, 2007 im using PHP version 5.2.3 In that case you'll want to change each instance of $HTTP_POST_FILES to $_FILES for a start. Then as MadTechie says, you can use $_FILES['ufile']['size'] to get the size. As for how you want to chose the file type, this can be either by extension or mime type. Regards Huggie any examples on how to do that mime? or the extensions? Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 any examples on how to do that mime? or the extensions? Yes actually, a search of these forums proved really fruitful. Give it a try, and if you don't have any luck then post back. Regards Huggie 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.