I have an upload script setup, but when I goto test it and upload a test picture it just sits there with the status bar going and never uploads the file. Can someone help me out? :X
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_dir = "/images/screenshot/";
$upload_url = $url_dir."screenshot/";
$message ="";
//create upload_files directory if not exist
//If it does not work, create on your own and change permission.
if (!is_dir("images/screenshot")) {
die ("upload_files directory doesn't exist");
}
if ($_FILES['userfile']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
//$message = "Invalid File Specified.";
}
print $message;
function do_upload($upload_dir, $upload_url) {
$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result = $_FILES['userfile']['error'];
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;
//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
//File Size Check
else if ( $file_size > 700000) {
$message = "The file size is over 700kb.";
return $message;
}
//File Type Check
else if ( $file_type == "text/plain" || $file_type == "exe" || $file_type == "zip" || $file_type == "rar") {
$message = "Sorry, You are only allowed to upload files of gif,jpg,jpeg or png type." ;
return $message;
}
$result = do_upload($temp_name, $file_path);
$message = ($result)?"File url
$file_url" :
"Somthing is wrong with uploading a file.";
return $message;
}
?>