Select only images to upload via the browse button

I want to create a file upload form.

But my confusion is that when I add a file element to html, it allows me to select all file types.

I want the browse button to allow images to be selected from the file system.

In fact, it should only display filesystem images.

Thanks in advance.

+3
source share
3 answers

Uploadify . , . , . , . .

+1

"" MIME, .

<input type="file" accept="image/gif, image/jpeg" />

JS http://swfupload.org/

+8

, , "accept" . :

$accept = array('jpg','png','gif','bmp');
$extension = substr($_FILES['file']['name'],strrpos($_FILES['file']['name'],'.')+1);

if(!in_array($extension,$accept)){
  // If the extension is not allowed show an error, else, the file type is valid
  echo 'Not a valid file extension';
}
+1

Source: https://habr.com/ru/post/1724712/


All Articles