Why am I getting this error?
I'm trying to upload a file and it's telling me I have the wrong extension.
Now I'm blocking everything but the extension but I'm giving it the right file and it's not allowing it through, why??
The file I am tring to upload is
C:\Users\me\my file.atn
The error I am getting is:
The file you are attempting to upload has the wrong extension.
PHP Code:
$userfile = $_FILES['action_id']['name'];
$file_size = $_FILES['action_id']['size'];
$file_temp = $_FILES['action_id']['tmp_name'];
$file_err = $_FILES['action_id']['error'];
$path = '../../downloads/photoshop/temp_actions/';
// Create a new file name
// This is so if other files on the server have the same name, it will be renamed
$randomizer = rand(0000, 9999);
$file_name = $randomizer.$userfile;
// Get the file type
// Using $_FILES to get the file type is sometimes inaccurate, so we are going
// to get the extension ourselves from the name of the file
// This also eliminates having to worry about the MIME type
$file_type = $userfile;
$file_type_length = strlen($file_type) - 3;
$file_type = substr($file_type, $file_type_length);
if(!empty($userfile)) {
echo 'File Uploaded Information
<ul>
<li>File being uploaded: ' .$userfile. '</li>
<li>File Type: .' .$file_type.'</li>
<li>File Size: ' .$file_size. 'KB </li>
<li>File Error: ' . $file_err. '</li>
</ul>';
// limit the size of the file to 20MB
if($file_size > 20971520) {
echo '<font color="#F0B80F"><b>The file you are trying to upload is too large. Please restrict your file to at least 20MB </b></font><BR />';
exit();
}
// Set allowed file types
// Set case of all letters to lower case
$file_type = strtolower($file_type);
$files = array();
$files[] = 'atn';
$files[] = 'aaa';
$files[] = 'bbb';
// Search the array for the allowed file type
$key = array_search($file_type, $files);
if($key) {
echo '<b>The file you are uploading is allowed. </b><br />';
} else {
echo '<font color="#F0B80F"><b>The file you are attempting to upload has the wrong extension. </b></font><br />';
exit();
}
// Check for errors and upload the file
$error_count = count($file_error);
if($error_count > 0) {
for($i = 0; $i <= $error_count; ++$i) {
echo $_FILES['action_id']['error'][$i];
}
} else {
if(move_uploaded_file($file_temp, '../../downloads/photoshop/temp_actions/' .$file_name.'')) {
echo 'Thank you for your contribution. You should see your action on the site within 24 hours.';
} else {
echo '<font color="#F0B80F"><b>Whoops look like there was a mistake during your upload. Please try again.</b></font>';
}
}
} else {
echo '<font color="#F0B80F"><b>No file has been selected.</b></font>';
}