We protect the site from loading everything except pictures
If you are afraid that the user may download a malicious script or files with viruses, that can harm the site, then read a new lesson from my site. I recently found an interesting piece of code in the form of a filter, which can be added to the file functions.php. If you want to restrict download access to everyone but yourself, then you can put it in an array $users your login.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
add_filter('upload_mimes','restrict_mime'); function restrict_mime($mimes) { global $current_user; get_currentuserinfo(); // change users in list $users = array( "ryan", "steven", "larry", "jerry" ); if (!in_array($current_user->user_login, $users)) { $mimes = array( 'jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', ); } return $mimes; } |
You can also add MIME types of files that are allowed to be used for uploading. Alternatively, you can add the following types:
1 2 3 |
'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff' |
Everything is working, I checked everything. If you want to see what types are allowed for you now, then read the article “Supported file types for upload” Good luck developing secure sites.
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.