I am building an uploader for a photo site, most of the photos that are uploaded are of type 1232132_1231231_12.jpg. when I run pathinfo() I am getting blank outputs for extension.
Here is my code
$target_dir = "Photos/";
$species = filter_input(INPUT_POST, 'species');
$country = filter_input(INPUT_POST, 'country');
$type= filter_input(INPUT_POST, 'type');
include_once 'connection.php';
echo $target_dir . basename($_FILES["file"]["name"]);
for($a=0;$a<count($_FILES['file']['tmp_name']);$a++)
{
$target_file = $target_dir . basename($_FILES["file"]["name"][$a]);
$imageFileType=pathinfo($target_file, PATHINFO_EXTENSION);
var_dump(pathinfo($target_file));
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" )
{
echo "<br> Sorry, only JPG, JPEG, PNG & GIF files are allowed. your file is a $imageFileType <br>";
}
}
Photos/2014-02-21 18.19.08.jpg
echo $target-file;
gives this output Photos/2014-02-21 18.19.08.jpg
for the var_dump this is echoed out to screen, array(3) { ["dirname"]=> string(6) "Photos" ["basename"]=> string(1) "2" ["filename"]=> string(1) "2" }
Is there something wrong with my code or does pathinfo() not work well with number and special character file names?
Is there another function that does work with these types of file names or should explode() the $target_file with the '.' and take the last element in the returned array?
\n";` right above your var_dump()? Is the filename "Photos/2" or "Photos/2.jpg"? – Peter Bowers Mar 29 '15 at 20:23