I have a video upload page for my customers. When they try to upload a file that has multiple dots in the file name, the file will not upload. I do not want my customers to have to change the file name. I need the periods removed or the file renamed before determining the file extension.
This filename “testfile.mov” will upload but this file “test.file.mov” will not upload.
My code:
$today=date(“Y-m-d”);
$name= $_FILES[‘file’][‘name’];
$tmp_name= $_FILES[‘file’][‘tmp_name’];
$position= strpos($name, “.”);
$fileextension= substr($name, $position + 1);
$fileextension= strtolower($fileextension);
$newfilename = $lastname.’-’ .$today.’.’.$fileextension;
if (isset($name)) {
$path= ‘uploads/videos/’;
if (empty($name))
{
echo “Please choose a file”;
}
else if (!empty($name)){
if (($fileextension !== “mp4”) && ($fileextension !== “ogg”) && ($fileextension !== “webm”) && ($fileextension !== “mov”))
{
echo “The file extension must be .mp4, .ogg, .webm, or .mov in order to be uploaded”;
}
else if (($fileextension == “mp4”) || ($fileextension == “ogg”) || ($fileextension == “webm”) || ($fileextension == “mov”))
{
if (move_uploaded_file($tmp_name, $path.$newfilename)) {
echo “Video uploaded.”;
} else {
echo “Sorry, there was an error uploading your file.”;
}
}
}