Jump to content

Php File Download


michaelkirby

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.