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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.