You're forgetting about using the copy() function with your PHP upload script.
When a file is uploaded, it is uploaded to the temporary files on your server, where you may probly never find it, lol.
Here's something I've written that will help you with the PHP end, including some file verification to protect you from most attacks.
<?php
/**
* File Upload Class
* Written by Michael Gillespie (Demonslay) <Michael_Todd_335@yahoo.com>
*
* Description:
* Handles file uploading, including error-handling, verification, and logging
*
* Usage:
* $upload =& new fileupload($_file, $dir, $options);
* $upload->upload_file();
*
* Example:
* HTML Form
* <form action="upload.php" enctype="multipart/form-data" method="post">
* <input type="file" name="file" value="Browse" />
* <input type="submit" value="Upload" />
* </form>
* PHP Script
* $upload = new fileupload('file', 'uploads', array('max_file_size' => 1024*50, 'ext_array' => array('.gif', '.jpg', '.png'), 'chmod' => 0777));
* $upload->upload_file();
*
* Parameters:
* (string) $_file - File input name (ex. 'file')
* (string) $dir - Directory to upload to (ex. 'uploads')
* (array) $options - Array of extra options for verification, such as max filesize and allowed extensions (optional)
* |_ (integer) 'max_file_size' - Max file size allowed to upload (ex. 1024*50 [50KB])
* |_ (integer) 'max_width' - Max width in pixels allowed for images (ex. 500)
* |_ (integer) 'max_height' - Max height in pixels allowed for image (ex. 500)
* |_ (array) 'ext_array' - Extensions allowed for upload (ex. array('.gif', '.jpg', '.png')
* |_ (integer 'chmod' - Chmod value to be allied to the file after uploading (ex. 0755)
*
* Notes:
* - Automatically returns custom errors
* - Can be called for multiple files - NOT compatable with multiple file arrays for single instance (ex. file[]) {needs custom patching}
*/
class fileupload{
/* Class Constructor
* See Document Above for Usage
*/
function __construct($_file, $dir = NULL, $options = array('max_file_size' => 512000, 'max_width' => 500, 'max_height' => 500, 'ext_array' => array('.gif', '.jpg', '.jpeg', '.png'))){
// Variable Check
if(!$_file){
$this->upload_error[] = 'No file defined.';
return false;
}
// Sets File Variables
$this->temp_file_name = $_FILES[$_file]['tmp_name'];
$this->file_name = $_FILES[$_file]['name'];
$this->file_size = $_FILES[$_file]['size'];
$this->file_type = $_FILES[$_file]['type'];
list($this->width, $this->height, $type, $attr) = getimagesize($_FILES[$_file]['tmp_name']);
// Sets Options
$this->max_file_size = ($options['max_file_size']) ? (int)$options['max_file_size'] : NULL;
$this->max_width = ($options['max_width']) ? (int)$options['max_width'] : NULL;
$this->max_height = ($options['max_height']) ? (int)$options['max_height'] : NULL;
$this->ext_array = ($options['ext_array']) ? $options['ext_array'] : false;
$this->chmod = ($options['chmod']) ? (int)$options['chmod'] : 0755;
// Verify Given Directory
$this->directory = $this->get_upload_directory($dir);
}
/* Class Destructor
* Automatically Called at End of Script
*/
function __destruct(){
// Report Any Errors
if($this->upload_error) $this->report_errors();
return true;
}
/* Validate Directory Function
* Automatically Called by Class Constructor
*/
function get_upload_directory($dir){
if(is_null($dir)) return NULL;
// Check if Upload Directory Given
if($dir){
// Make Sure Directory Ends in Trailing Slash
$last_slash = substr($dir, (strlen($dir) - 1), 1);
$dir = ($last_slash != '/') ? $dir.'/' : $dir;
// Attempt to Open Directory
if($handle = @opendir($dir)){
closedir($handle);
return $dir;
}
else{
// Return Internal Error
$this->upload_error[] = "Upload directory {$dir} could not be opened.";
return false;
}
}
else{
// Return Internal Error
$this->upload_error[] = 'No upload directory defined.';
return false;
}
}
/* Validate Extension Function
* Automatically Called by run_validation()
*/
function validate_extension(){
// Variables
$extension = strtolower(strrchr($this->file_name, '.'));
if(!$this->ext_array) return true;
foreach($this->ext_array as $value){
$first_char = substr($value, 0, 1);
$extensions[] = ($first_char <> '.') ? '.'.strtolower($value) : strtolower($value);
}
// Validate File Extension Against Allowed Extensions
foreach($extensions as $value){
if($value == $extension) $valid_extension = true;
}
// Return if Extension is Valid
if($valid_extension) return true;
else{
// Return Extension Error
$this->upload_error[] = "Extension {$extension} not allowed.";
return false;
}
}
/* Validate File Size Function
* Automatically Called by run_validation()
*/
function validate_size(){
if(!$this->file_size){
// Return No Upload Error
$this->upload_error[] = 'No file was uploaded.';
return false;
}
if($this->file_size > $this->max_file_size){
// Return Filesize Error
$this->upload_error[] = "Filesize {$this->read_filesize($this->file_size)} exceeds the max file size of {$this->read_filesize($this->max_file_size)}.";
return false;
}
else return true;
}
/* Validate File Dimensions
* Automatically Called by run_validation()
*/
function validate_dimensions(){
// Return True if No Dimension Limitations
if(!$this->max_width || !$this->max_height) return true;
if($this->width > $this->max_width){
// Return File Width Error
$this->upload_error[] = "Image width of {$this->width} pixels exceeds max width of {$this->max_width} pixels.";
return false;
}
if($this->height > $this->max_height){
// Return File Height Error
$this->upload_error[] = "Image height of {$this->height} pixels exceeds max height of {$this->max_height} pixels.";
return false;
}
return true;
}
/* Validate File Exist Function
* Automatically Called by run_validation()
*/
function validate_file(){
$file = $this->directory.$this->file_name;
if(file_exists($file)){
// Return File Exists Error
$this->upload_error[] = "File <a href=\"{$file}\" target=\"_blank\">{$file}</a> already exists.";
return false;
}
else return true;
}
/* Validate Upload File Stability
* Automatically Called by run_validation()
*/
function validate_upload(){
if($this->file_error){
// Return Upload Errors
switch($error){
case UPLOAD_ERR_OK: return true;
case UPLOAD_ERR_INI_SIZE:
$this->upload_error[] = "Filesize {$this->read_filesize($this->file_size)} exceeds the server max file size of ".$this->read_filesize(ini_get('upload_max_filesize')).'.';
return false;
case UPLOAD_ERR_FORM_SIZE:
$this->upload_error[] = "Filesize {$this->read_filesize($this->file_size)} exceeds the form max filesize of ".$this->read_filesize((int)$_POST['MAX_FILE_SIZE']).'.';
return false;
case UPLOAD_ERR_PARTIAL:
$this->upload_error[] = 'The uploaded file was only partially uploaded.';
return false;
case UPLOAD_ERR_NO_FILE:
$this->upload_error[] = 'No file was uploaded.';
return false;
case UPLOAD_ERR_NO_TMP_DIR:
$this->upload_error[] = 'The temporary directory could not be found for upload to.';
return false;
case UPLOAD_ERR_CANT_WRITE:
$this->upload_error[] = 'Failed to write file to disk.';
return false;
default:
$this->upload_error[] = 'Unknown file error.';
return false;
}
}
else return true;
}
/* Validate Upload by HTTP POST Method
*/
function validate_http(){
if(!is_uploaded_file($this->temp_file_name)){
$this->upload_error[] = 'File not uploaded by HTTP POST method.';
return false;
}
else return true;
}
/* Run All Validation Functions
* Automatically Called by upload_file()
*/
function run_validation($run = array('size', 'dimensions', 'extension', 'upload', 'file', 'http')){
foreach($run as $r){
if(is_callable(array($this, 'validate_'.$r))) call_user_func(array(&$this, 'validate_'.$r), $data);
}
return (!$this->upload_error) ? true : false;
}
/* Upload File
*/
function upload_file(){
// Validate File
if(!$this->run_validation(array('size', 'dimensions', 'extension', 'upload', 'file', 'http'))){
// Return Invalid File Upload Error
$this->upload_error[] = 'File not valid to upload.';
return false;
}
// Attempt to Move File to Server
if(move_uploaded_file($this->temp_file_name, $this->directory.$this->file_name)){
if(!chmod($this->directory.$this->file_name, octdec($this->chmod))){
// Return CHMOD Error
$this->upload_error[] = "Could not CHMOD file to value of '{$this->chmod}'.";
}
// Attempt to Log
$this->log_file();
return true;
}
else{
// Return Internal Error
$this->upload_error[] = 'File could not be moved.';
return false;
}
}
/* Return All Errors
* Automatically Called by Class Destructor
*/
function report_errors(){
// If Errors Exist
if($this->upload_error){
// Echo Each Error with Format
foreach($this->upload_error as $error) echo '<p class="error"><span class="dred"><strong>Upload Error:</strong></span> '.$error.'</p>';
}
else return false;
}
}
$upload = new fileupload('Filedata', 'uploads', array('max_file_size' => 1024*50, 'ext_array' => array('.gif', '.jpg', '.png'), 'chmod' => 0777));
$upload->upload_file();
?>