$doc_root=$_SERVER['DOCUMENT_ROOT']."/"; $dir='images/content/'; $userfile=$HTTP_POST_FILES['imagefile']['name']; $userfile_size=$HTTP_POST_FILES['imagefile']['size']; $tmp_upload_file=$HTTP_POST_FILES['imagefile']['tmp_name']; $new_file_name=$dir.$userfile; if ( $userfile == "none" ) { $error_msg = "You did not specify a file for uploading."; return; } if ( $userfile_size > 2097152 ) { $error_msg = "Sorry, your file is too large."; return; } if ($fd = fopen ($tmp_upload_file,"rb")) { $cnt = fread ($fd,$userfile_size); fclose ($fd); } else { $error_msg = "Sorry, Can't read file."; return; } if ($fp=fopen($doc_root.$dir.$userfile,"wb")) { fputs($fp,$cnt); fclose($fp); chmod($doc_root.$dir.$userfile,0666); } else { $error_msg = "Sorry, Can't write file."; return; } |