09/10/2018, 18:22
Cách Tạo Một Web Upload Như Thế Nào ?
Xin hỏi : Tôi có một cái Host có hỗ trợ đầy đủ. Mỗi khi ra tiệm Net, thì tôi phải cài đặt chương trình Upload như LeaFTP, Cute....thì mới Upload lên Host được. Nhưng nay tôi muốn tạo ra 1 trang web có chức năng cho phép Upload 1 hay 2 file cũng được mà không cần phải đăng nhập Username và Password mà đi bất cứ đâu tôi cũng có thể Upload được thông qua trang web của mình . Tôi rất mong được sự giúp đỡ của ban quản trị trang web. Xin cảm ơn.
Bài liên quan
muốn up ở đâu thì đặt nó ở đó:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
//một script giúp bạn upload file lên server
//code by Vodanh (vodanh@yahoo.com)
$site_name = $_SERVER***91;'HTTP_HOST'***93;;
$url_dir = "http://".$_SERVER***91;'HTTP_HOST'***93;.dirname($_SERVER***91;'PHP_SELF'***93;);
$url_this = "http://".$_SERVER***91;'HTTP_HOST'***93;.$_SERVER***91;'PHP_SELF'***93;;
$upload_dir = "";
$upload_url = $url_dir."/";
$dir = opendir(".");
$message ="";
if ($_FILES***91;'userfile'***93;) {
$message = do_upload($upload_dir, $upload_url);
}
print $message;
function do_upload($upload_dir, $upload_url) {
$temp_name = $_FILES***91;'userfile'***93;***91;'tmp_name'***93;;
$file_name = $_FILES***91;'userfile'***93;***91;'name'***93;;
$file_type = $_FILES***91;'userfile'***93;***91;'type'***93;;
$file_size = $_FILES***91;'userfile'***93;***91;'size'***93;;
$result = $_FILES***91;'userfile'***93;***91;'error'***93;;
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;
//Kiểm tra tên file
if ( $file_name =="") {
$message = "Tên file không hợp lệ";
return $message;
}
//Kiểm tra dung lượng file upload
// ở đây tôi sét là 5mb
else if ( $file_size > 5000000) {
$message = "The file size is over 5mb.";
return $message;
}
//Kiểm tra kiểu file upload
else if ( $file_type == "text/plain" ) {
$message = "Sorry, Bạn không thể upload script file" ;
return $message;
}
//Upload file
$result = move_uploaded_file($temp_name, $file_path);
$message = ($result)?"Url file đã upload <a href='.$file_url.'>$file_url</a>" :
"Có lỗi trong quá trình upload file.";
return $message;
}
?>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
File upload :<input type="file" id="userfile" name="userfile">
<input type="submit" name="upload" value="Upload">
</form>
<?php
// hiển thỉ danh sách các file trong thư mục uploads - nvc@vietel.com.vn
while (FALSE !== ($file = readdir($dir))) {
if (is_dir($file)) {
//doc tên thư mục
echo "<a href=\"$file\"><span class=\"directory\">$file/</span></a><br>\n";
} else
//doc ten file
$non_dirs***91;***93; = "<a href=\"$file\">$file</a><br>\n";
}
foreach ($non_dirs as $value) {
echo $value;
}
closedir($dir);
?>
</body>
</html>
http://saothang8.net/software/PHPscript/
---->>>cacthukhac/obiefileman.zip