Here's a function I usually use to upload stuff in php:
/**
* Causes a file to be downloaded to the client.
*
* @param string $source_filename The name of the file to download, as it exists on the server.
* @param string $save_as_filename The name of the file to download, as it is suggested to the user in a Save As-dialog.
*
* @return int The number of bytes downloaded,
* or bool false on failure.
*/
function download_file($source_filename, $save_as_filename)
{
$file = $pathinfo($filename);
switch (strtolower($file['extension'])) {
case 'pdf': $content_type = 'application/pdf'; break;
case 'exe': $content_type = 'application/octet-stream'; break;
case 'zip': $content_type = 'application/zip'; break;
case 'doc': $content_type = 'application/msword'; break;
case 'xls': $content_type = 'application/vnd.ms-excel'; break;
case 'ppt': $content_type = 'application/vnd.ms-powerpoint'; break;
case 'gif': $content_type = 'image/gif'; break;
case 'png': $content_type = 'image/png'; break;
case 'jpg': $content_type = 'image/jpg'; break;
default : $content_type = 'application/force-download'; break;
}
if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
header('Pragma: public'); // If this is left out, apparently IE can give problems downloading unusual file types (->page not found)
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: ' . $content_type);
header('Content-Disposition: attachment; filename=' . $save_as_filename);
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($source_filename));
return readfile($source_filename);
}