getClientFilename()); $uploadOk = 1; $imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION)); // Check if file already exists if (file_exists($targetFile)) { return "The file already exists"; } // Check file size if ($img->getSize() > 2000000) { return "The file is too large, max 2MB"; } // Allow certain file formats if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") { return "Only JPG, JPEG, PNG & GIF files are allowed"; } $img->moveTo($targetFile); return array("imgLocation" => $targetFile); } }