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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -