How can WordPress support uploading images?

WBOY
Release: 2016-07-25 08:52:04
Original
950 people have browsed it
This article introduces the implementation method of WordPress only supporting the uploading of pictures. It uses a custom function to implement the picture upload function and does not allow other files to be uploaded. Friends who need it can refer to it.

wordpress supports uploading images

When adding articles, WordPress supports adding media, including pictures, videos, word and excel and other multimedia files. To obtain all file types that WordPress supports uploading, you can insert the following php code in functions.php of the current theme. Then, open the blog homepage and view the source code of the webpage to see a complete support list (bbs.it-home.org Script School): print_r(wp_get_mime_types());

How to make wordpress only support uploading image files and refuse to upload other files.

Insert in your current theme’s functions.php:

// add the filter
add_filter('upload_mimes', 'custom_upload_mimes');

function custom_upload_mimes( $existing_mimes=array() ) {
  $existing_mimes = array('jpg|jpeg|jpe' => 'image/jpeg',
    'gif' => 'image/gif',
    'png' => 'image/png',
    'bmp' => 'image/bmp',
    'tif|tiff' => 'image/tiff',
    'ico' => 'image/x-icon');

  return $existing_mimes; 
}
Copy after login

You can now only support uploading pictures and refuse to upload other files.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template