แนะนำสคริปอับโหลดและพรีวิวภาพครับ
หวังว่าจะมีประโ ยชน์สำหรับมือใ หม่หัดขับนะครับ
แบ่งออกเป็น 3 ไฟล์นะครับ
ไฟล์ที่ 1 เอาไว้โชว์ภาพ ในที่นี้ผมตั้งเป็น index.html
Code
01.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
02.
<html xmlns="http://www.w3.org/1999/xhtml">
03.
<head>
04.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
05.
<title>Untitled Document</title>
06.
<script type="text/javascript">
07.
function popupUploadImage( f_name, e_name, path ) {
08.
window.open("./popUploadImages.php","name","top=300,left=450,height=250,width=400, status=1");
09.
}
10.
11.
</script>
12.
13.
</head>
14.
15.
<body>
16.
<img src="" name="pImage" id="pImage"/>
17.
[br /]
18.
<a href="#" onclick="popupUploadImage();">>[ Browse ][/url][br /]
19.
</body>
20.
</html>
ไฟล์ที่ 2 popUploadImages.php
Code
01.
<html>
02.
<head>
03.
<title>Upload Images</title>
04.
</head>
05.
06.
<body>
07.
<form name="uploadImage" action="uploadImages.php" method="post" enctype="multipart/form-data">
08.
<table width="400" border="0" cellspacing="0" cellpadding="0">
09.
<tr>
10.
<td class="darkbrown12_bold">?</td>
11.
</tr>
12.
<tr>
13.
<td class="darkbrown12_bold"><div align="center">Select Image</div></td>
14.
</tr>
15.
<tr height="35">
16.
<td align="center"><input type="file" name="file" class="inputBox" size="30"></td>
17.
</tr>
18.
<tr height="35">
19.
<td align="center">?</td>
20.
</tr>
21.
<tr height="35">
22.
<td align="center">
23.
<input type="submit" name="submitPage" value="upload" class="button80">
24.
</td>
25.
</tr>
26.
</table>
27.
</form>
28.
</body>
29.
</html>
ไฟล์ที่ 3 uploadImages.php
Code
01.
<?php
02.
03.
if($file){
04.
$path = "images/";
05.
$fileType = explode('.', $file_name);
06.
$fileName = date('YmdHis');
07.
$fileName = $fileName.".".$fileType[1];
08.
$uploadFile = $path."".$fileName;
09.
copy($file, $uploadFile);
10.
11.
12.
$img = "./images/$fileName";
13.
$Ipreview = "pImage";
14.
15.
16.
}
17.
18.
?>
19.
20.
<html>
21.
<head>
22.
23.
<script language="javascript">
24.
function returnValue() {
25.
window.opener.document.getElementById('<? echo $Ipreview?>').src = "<?php echo $img ?>";
26.
window.close();
27.
}
28.
</script>
29.
</head>
30.
<body onLoad="returnValue()">
31.
</body>
32.
</html>
มาจากที่นี่...
http://www.thaicreate.com/free-web-script/upload-preview.htmlตรงนี้มีภาพ! แต่ท่านจะมองไม่เห็น , ท่านต้อง สมัครสมาชิก หรือ
ลงชื่อเข้าระบบ