|
 |
|
เวลาคลิก Browse เลือกไฟล์ข้อมูลจะมองเห็นเฉพาะไฟล์ Word หรือ PFD เท่านั้นด้วยภาษา PHP หรืออื่น ๆ ช่วยทีครับ !!! Thx |
|
 |
|
|
 |
 |
|
ถ้า HTML เลยคงไม่มีครับ (หรือว่ามีว่า) เพราะ attr accept ของ input file มันใช้ได้แต่ nescape browser ลองใช้ PHP หรือ Javascript ตรวจสอบค่าไฟล์ที่เข้ามาว่าใช่ที่เราต้องการหรือป่าว น่าจะเป็นทางออก
หรือจะลองใช้ Uploadify ก็น่าจะตรงตามที่ต้องการนะ สามารถกำหนดนามสกุลไฟล์ที่ต้องการและ filter ไฟล์ขณะเลือกได้
http://www.uploadify.com/
|
 |
 |
 |
 |
Date :
2011-11-20 19:05:47 |
By :
zankumuro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ้อ ครับ ยังไงจะลองดูน่ะครับ
ขอบพระคุณมากเลยคับ
|
 |
 |
 |
 |
Date :
2011-11-23 22:55:51 |
By :
supachai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<!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" />
<title>Untitled Document</title>
<script type="text/javascript">
function chk(){
fty=new Array(".gif",".jpg",".jpeg",".png"); // ประเภทไฟล์ที่อนุญาตให้อัพโหลด
a=document.form1.artist_picture.value; //กำหนดค่าของไฟล์ใหกับตัวแปร a
permiss=0; // เงื่อนไขไฟล์อนุญาต
a=a.toLowerCase();
if(document.form1.artist_picture.value!=""){
for(i=0;i<fty.length;i++){ // วน Loop ตรวจสอบไฟล์ที่อนุญาต
if(document.form1.artist_picture.value.lastIndexOf(fty[i])>=0){ // เงื่อนไขไฟล์ที่อนุญาต
permiss=1;
break;
}else{
continue;
}
}
if(permiss==0){
alert("อัพโหลดได้เฉพาะไฟล์ gif jpg jpeg png");
return false;
}
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" enctype="multipart/form-data" onsubmit="return chk();" action="">
<input name='artist_picture' id="artist_picture" type='file'>
<input type='submit' name='Submit' value=' บันทึก '>
</form>
<? $fileupload=$_FILES['artist_picture']['tmp_name'];
$fileupload_name=$_FILES['artist_picture']['name'];
$fileupload_size=$_FILES['artist_picture']['size'];
$fileupload_type=$_FILES['artist_picture']['type'];
if ($fileupload) {
$array_last=explode(".",$fileupload_name);
$c=count($array_last)-1; $lastname=strtolower($array_last[$c]) ;
if ($lastname=="gif" or $lastname=="jpg" or $lastname=="jpeg" or $lastname=="png") {
copy($fileupload,"upload/".$fileupload_name);
//-- โค้ด ปรับขนาดของภาพ --//
$images = "upload/".$fileupload_name;
$height = 255; //กำหนดขนาดความสูง
$size = getimagesize($images);
$width = round($height*$size[0]/$size[1]); //ขนาดความกว้่างคำนวนเพื่อความสมส่วนของรูป
if($size[2] == 1) {
$images_orig = imagecreatefromgif($images); //resize รูปประเภท GIF
}else if($size[2] == 2) {
$images_orig = imagecreatefromjpeg($images); //resize รูปประเภท JPEG
}else if($size[2] == 3) {
$images_orig = imagecreatefrompng($images); //resize รูปประเภท png
}
$photoX = imagesx($images_orig);
$photoY = imagesy($images_orig);
$images_fin = imagecreatetruecolor($width, $height);
imagecopyresampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
imagejpeg($images_fin, $images); //ชื่อไฟล์ใหม่
imagedestroy($images_orig);
imagedestroy($images_fin);
//-- โค้ด ปรับขนาดของภาพ --//
echo "<h2> Upload รูปภาพเรียบร้อยแล้วครับ </h2>";
echo "<img src='upload/$fileupload_name'>";
}else{
echo "<h3>ERROR : ไม่สามารถ Upload รูปภาพ</h3>";
}
unlink($fileupload);
}else{
echo "<h3>ERROR : ไม่สามารถ Upload รูปภาพ</h3>";
}
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2011-11-24 11:59:04 |
By :
supachai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค้ด ด้านบน สำหรับ ตรวจสอบชนิดข้อมูล ภาพ .gif / .jpeg / .jpg / .png
ซึ่งในส่วน Javascript จะเป้นการตรวจสอบ ว่า ไฟล์ ที่เลือกเข้ามานั้น เป็น .gif / .jpeg / .jpg / .png หรือไม่
ถ้าไม่ จะ MessageBox เตือน "อัพโหลดได้เฉพาะไฟล์ gif jpg jpeg png"
และถ้าหากใครอยากเปลี่ยนเป็น ไฟล์ ชนิดอื่น
ก็สามารถเปลี่ยน ในโค้ดส่วนนี้
จากเดิม
if ($lastname=="gif" or $lastname=="jpg" or $lastname=="jpeg" or $lastname=="png") {
copy($fileupload,"upload/".$fileupload_name);
เป็น
if ($lastname=="pdf" or $lastname=="msword" or $lastname=="vnd.ms-excel") {
copy($fileupload,"upload/".$fileupload_name);
แต่ต้องลบโค้ดในส่วน
//-- โค้ด ปรับขนาดของภาพ --//
ออก เพราะเราเปลี่ยนเป็นไฟล์ชนิดข้อมูล หากไม่ลบออก จะขึ้น Error แต่ ก็สามารถเพิ่มข้อมูลได้อยู่เช่นกัน
สุดท้ายหวังว่าคงจะเข้าใจและก็สามารถนำไปปรับใช้กันได้

|
 |
 |
 |
 |
Date :
2011-11-24 12:06:59 |
By :
supachai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เค้าคงจะหมายถึงให้ Browser เห็นเฉพาะไฟล์นามสกุลที่กำหนดหรือเปล่าครับ
น่าจะ Login น่ะครับ จะได้กด +Thanks ให้ครับ 
|
 |
 |
 |
 |
Date :
2011-11-24 12:41:09 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Login แล้ว น่ะครับ
พึ่งสมัครใหม่ นะครับ 
|
 |
 |
 |
 |
Date :
2011-12-03 22:36:59 |
By :
YondaiMe13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|