php is_file not detecting image with period in name -
i have function checks if image files exist. works images, except when period inside filename. filenames user uploaded, , many exist not sanitized. here example:
$img = 'nice_name.jpg'; // detects $img = 'bad_name.7.jpg'; // doesn't detect if (is_file($path . $img)) { return $path . $prefix . $img; } i'm not sure how escape or make work. have doubled checked , file exist @ path. function works other image names in same folder.
edit: marked duplicate , linked question uploading files. using is_file() check if file exists. there no uploading occurring, , file has "." in name on server, different issue.
you can use basename() file name, , it, rename if contains period.
$testfile = "test.7.img"; $extension = ".img"; $filename = basename($testfile, $extension); if(strpos($filename,".") > 0) { $newname = str_replace(".","",$filename) . $extension ; rename($testfile,$newname); } //... continue on code
Comments
Post a Comment