lobski Posted July 24, 2008 Share Posted July 24, 2008 Greetings. I followed the PHP uploading tutorial, and I want to change a few things to it. First is to restrict the uploaded file to ONLY image files, such as jpeg, gif, png, etc. I am following the tutorial here: http://www.tizag.com/phpT/fileupload.php So far I have this code: <input type="hidden" name="MAX_FILE_SIZE" value="250000" /> Select image to upload: <input name="uploadedfile" type="file" /> <input type="submit" value="Upload File" /> </form> What would I have to change to restrict the files to images? Link to comment https://forums.phpfreaks.com/topic/116355-how-to-add-restrictions-on-my-little-code/ Share on other sites More sharing options...
trq Posted July 24, 2008 Share Posted July 24, 2008 The code you have posted is html, not php. If you want to insure your uploaded files are images you can use getimagesize, this will return false if given a filename which isn't an image. Link to comment https://forums.phpfreaks.com/topic/116355-how-to-add-restrictions-on-my-little-code/#findComment-598282 Share on other sites More sharing options...
lobski Posted July 24, 2008 Author Share Posted July 24, 2008 Edit function disabled on the forums? Anyway, I pasted in the wrong one... Here's the correct code: <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has successfully been uploaded."; } else{ echo "There was an error uploading the file, please try again!"; } ?> Link to comment https://forums.phpfreaks.com/topic/116355-how-to-add-restrictions-on-my-little-code/#findComment-598320 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 <?php $target_path = "uploads/"; if(getimagesize($_FILES['uploadedfile']['tmp_name'])) { $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has successfully been uploaded."; } else{ echo "There was an error uploading the file, please try again!"; } } else { die("Was not a Image!"); } ?> You can give that a try, however I don't think it is right. Link to comment https://forums.phpfreaks.com/topic/116355-how-to-add-restrictions-on-my-little-code/#findComment-598322 Share on other sites More sharing options...
lobski Posted July 24, 2008 Author Share Posted July 24, 2008 <?php $target_path = "uploads/"; if(getimagesize($_FILES['uploadedfile']['tmp_name'])) { $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has successfully been uploaded."; } else{ echo "There was an error uploading the file, please try again!"; } } else { die("Was not a Image!"); } ?> You can give that a try, however I don't think it is right. I think that worked... Lastly, I would like to output the exact full URL of the file. Now I want to output 2 versions of the URL, a regular one, and a url with [/img] wrappers around it. How would I do this? ??? Link to comment https://forums.phpfreaks.com/topic/116355-how-to-add-restrictions-on-my-little-code/#findComment-598329 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 wrappers ? Link to comment https://forums.phpfreaks.com/topic/116355-how-to-add-restrictions-on-my-little-code/#findComment-598331 Share on other sites More sharing options...
lobski Posted July 24, 2008 Author Share Posted July 24, 2008 wrappers ? Yeah, I just want it to output to the user: http://www.awesome.com/uploads/image.jpg & [img=http://www.awesome.com/uploads/image.jpg] I also forgot to ask, where should I put in size limitations? Link to comment https://forums.phpfreaks.com/topic/116355-how-to-add-restrictions-on-my-little-code/#findComment-598335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.