Hello all,
I am trying to script it where when you upload a file it goes to a directory outside of the wwwroot folder. I am using IIS 6.0 on windows server 2003 machine. Here is my code below:
<?php
// Configuration - Your Options
$allowed_filetypes = array('.doc','.docx','.rtf'); // These will be the types of file that will pass the validation.
$max_filesize = 5242880.00000001; // Maximum filesize in BYTES (currently 5MB).
$upload_path = './resumes/'; // The place the files will be uploaded to.
$filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
$filename = preg_replace('"\.(doc|docx)$"', '.rtf', $filename);
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The filetype you attempted to upload is not allowed.<br><br>Please <a href="javascript:javascript:history.go(-1)">go back</a> and try again.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.<br><br>Please <a href="javascript:javascript:history.go(-1)">go back</a> and try again.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('The file could not be uploaded to the specified directory.<br><br>Please <a href="javascript:javascript:history.go(-1)">go back</a> and try again.');
// Upload the file to your specified path.
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
{header( "Location: http://www.mydomain.com/upload1.php" );} // It worked.
else
{header( "Location: http://www.mydomain.com/error.php" );} // It failed :(.
?>
Where I have the files going currently is a folder inside the directory entitled "resumes" but I want it to go to a separate directory. I have made a folder on the E: drive of the machine with the same folder name. I just don't know how to script it in php to make it do that. Can someone help me out? It would be much appreciated.
Thanks,
urbanrf