Hi all, i've got a script that i've part edited to accept only certain file types to be uploaded, eg; JPG, PNG, JPEG etc. the script is originally part of the "uploadify script", im new to php so im finding it hard to work out how i can add a function to rename files on the backend so i dont get duplicates or errors on upload, but keep original names for the frontend. if this all makes sense, thanks in advance - Cody
Code:
<?php
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
?>