michaelkirby Posted April 19, 2010 Share Posted April 19, 2010 Hi all, I'm looking to introduce a file download into my website but not really sure how to go about it. Anyone got any good pointers? Thanks Link to comment https://forums.phpfreaks.com/topic/198991-php-file-download/ Share on other sites More sharing options...
ScotDiddle Posted April 19, 2010 Share Posted April 19, 2010 michaelkirby, Use javascript to allow only specific file-types... The following code limits downloads to your server to images only... The onBlur prevents users from typing in anything into the input box... HTML: <form id="frontFile" name="frontFile"> <input class="style11" onChange="TestFileType(this.form.frontFile.value, ['gif', 'jpg', 'png', 'bmp', 'jpeg']);" id=frontFileImage name=frontFileImage onKeyDown="this.blur(); alert('Use Browse Button !');" onContextMenu="return false;" type="file" /><br /> </form> JavaScript: function TestFileType( fileName, fileTypes ) { if (!fileName) return; dots = fileName.split(".") //get the part AFTER the LAST period. fileType = "." + dots[dots.length-1]; return (fileTypes.join(".").indexOf(fileType) != -1) ? none() : alert("Please only upload files that end in types: \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again."); } Hope this helps... Scot L. Diddle, Richmond VA Link to comment https://forums.phpfreaks.com/topic/198991-php-file-download/#findComment-1044791 Share on other sites More sharing options...
ignace Posted April 19, 2010 Share Posted April 19, 2010 The following code limits downloads to your server to images only... No it doesn't I can just remove all those extra lines and upload any file I want (using FireBug). Disabling JavaScript even does the trick. Link to comment https://forums.phpfreaks.com/topic/198991-php-file-download/#findComment-1044851 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.