Phpman88 Posted December 3, 2021 Share Posted December 3, 2021 I recently submitted a plugin to WordPress and they told me to sanitize my file name here is the examples they gave me. Quote basename is great, but you also want to sanitize the filenames image-framer/image-framer.php:135: $targetFile = $targetPath . '/imageframer/' . basename($_FILES['image']['name'][$i]); image-framer/image-framer.php:138: $returnResponse[$i] = $dir['baseurl'] . '/imageframer/' . $_FILES['image']['name'][$i]; image-framer/image-framer.php:162: $targetFile = $targetPath . '/imageframer/' . basename($_FILES['uploadimg']['name']); image-framer/image-framer.php:165: $returnResponse = $dir['baseurl'] . '/imageframer/' . $_FILES['uploadimg']['name']; image-framer/src/Validation.php:13: $imageFileType = strtolower(pathinfo($targetPath . '/imageframer/' . basename($_FILES['image']['name'][$index]), PATHINFO_EXTENSION)); How would I go about sanitizing file names? Thanks all for your help. Quote Link to comment https://forums.phpfreaks.com/topic/314265-sanitize-file-names-wordpress/ Share on other sites More sharing options...
maxxd Posted December 3, 2021 Share Posted December 3, 2021 WP offers several sanitization functions - looks like you need sanitize_file_name(). Quote Link to comment https://forums.phpfreaks.com/topic/314265-sanitize-file-names-wordpress/#findComment-1592388 Share on other sites More sharing options...
Jasperleo654 Posted May 15, 2022 Share Posted May 15, 2022 On 12/3/2021 at 9:37 AM, Phpman88 said: I recently submitted a plugin to WordPress and they told me to sanitize my file name here is the examples they gave me. image-framer/image-framer.php:135: $targetFile = $targetPath . '/imageframer/' . basename($_FILES['image']['name'][$i]); image-framer/image-framer.php:138: $returnResponse[$i] = $dir['baseurl'] . '/imageframer/' . $_FILES['image']['name'][$i]; image-framer/image-framer.php:162: $targetFile = $targetPath . '/imageframer/' . basename($_FILES['uploadimg']['name']); image-framer/image-framer.php:165: $returnResponse = $dir['baseurl'] . '/imageframer/' . $_FILES['uploadimg']['name']; image-framer/src/Validation.php:13: $imageFileType = strtolower(pathinfo($targetPath . '/imageframer/' . basename($_FILES['image']['name'][$index]), PATHINFO_EXTENSION)); How would I go about sanitizing file names? Thanks all for your help. A year ago, I was also searching for its answer, but today I know. Quote Link to comment https://forums.phpfreaks.com/topic/314265-sanitize-file-names-wordpress/#findComment-1596276 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.