4

Change the default download dialog to PHP

 3 years ago
source link: https://www.codesd.com/item/change-the-default-download-dialog-to-php.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Change the default download dialog to PHP

advertisements

This is the typical upload code to bring up the dialog box:

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

When the popup window comes up, it shows ALL FILES, is there a way to filter this by any way? (by file extension, by file name, by whatever..) BEFORE the user chooses a file?

Cause until now, the only way I know is to wait until the user chooses whatever file he pleases (since all files are showing) just to filter it later and tell him he made a mistake picking the wrong file format.


PHP does not interact with the user browser in that way, however, you can use HTML to preset the extension of the files by specifying it in the html input. Here's an example for images:

<input type="file" name="fileToUpload" id="fileToUpload"
   accept="image/x-png,image/gif,image/jpeg" />

Or even:

<input type="file" name="fileToUpload" id="fileToUpload" accept="image/*" />

Read more about it here.


Note: The user may still be able to select files other than the ones you specify, so you need to check the extension server side.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK