hi all,

i am having a upload files field with browse button...Now
what i want actually is when i click the button "Browse..." the popup screen will popup, then normally it will browse all the files(doc, html,xls....) but i just want it to show the *.doc files ....so can any one help me..

Thank u

Dani AI

Generated

Short answer for : use the input element's accept attribute as a client-side hint so the file picker shows Word files (for example .doc, .docx and their MIME types). Support was spotty in 2010 (as noted), but modern browsers will typically filter the dialog. This is only a UI convenience and can be bypassed, so it must not be treated as security.

Example HTML (client-side hint):

<input type="file" accept=".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document">

Always validate uploads on the server. For PHP, use the FileInfo extension to get the true MIME type and check the extension/size before accepting:

<?php
if (!empty($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime = $finfo->file($_FILES['file']['tmp_name']);
$ext = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));
$allowed_mimes = ['application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document'];
$allowed_exts = ['doc','docx'];
if (!in_array($mime, $allowed_mimes) || !in_array($ext, $allowed_exts)) {
// reject upload
}
}
?>

A note on 's point: Flash/Silverlight uploaders were used historically for richer controls, but they are obsolete. For enhanced UX now, use the HTML5 File API and a JavaScript uploader library rather than plugin-era technologies. Official docs: input type=file (MDN) and PHP FileInfo finfo_file.

Recommended Answers

All 2 Replies

Only place I have seen this kind of functionality is with Flash, Silverlight and Gears uploaders.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.