|
 |
|
รบกวนหน่อยคับ อยากทราบว่าโค้ดแบบนี้จะต้องสร้างฐานข้อมูล SQL |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
$imageupload = $_FILES['imageupload']['tmp_name'];
$imageupload_name = $_FILES['imageupload']['name'];
$path = "uploads";
$newwidth=500;
if(isset($_POST['submit'])){
if($imageupload){
$arraypic = explode(".",$imageupload_name);
$filename = strtolower($arraypic[0]); //แปลงเป็นตัวพิมพ์เล็ก
$filetype = strtolower($arraypic[1]);
if($filetype=="jpg" || $filetype=="jpeg" || $filetype=="png"
|| $filetype=="gif"){
if($filetype=="jpg" || $filetype=="jpeg"){
$src = imagecreatefromjpeg($imageupload);
}
else if($filetype=="png"){
$src = imagecreatefrompng($imageupload);
}
else if($filetype=="gif"){
$src = imagecreatefromgif($imageupload);
}
list($width,$height)=getimagesize($imageupload);
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
if($filetype=="jpg" || $filetype=="jpeg"){
imagejpeg($tmp,$path."/".$filename.".".$filetype);
}
else if($filetype=="png"){
imagepng($tmp,$path."/".$filename.".".$filetype);
}
else{
imagegif($tmp,$path."/".$filename.".".$filetype);
}
}else {
echo "<div><center><h3>ERROR : ไม่สามารถ Upload รูปภาพได้</h3></center></div>";
}
}
}
$showpic = $path."/".$filename.".".$filetype;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<style>
body{background: #eeeeee;margin:0 auto;}
#form_upload{margin:0px auto;}
#showimage{margin:100px auto 20px auto;}
</style>
</head>
<body>
<center><div id="showimage">
<?php if($_POST[submit]){ echo "<a href='$showpic'>
<img width=150 src='$showpic'></img></a>";}?>
</div></center>
<div id="form_upload">
<form method="post" enctype="multipart/form-data">
<center> Image: <input name="imageupload" type="file" size="35"/>
<input type="submit" name="submit" value="Upload"/></center>
</form>
</div>
</body>
</html>
Tag : PHP, MySQL, Ms SQL Server 2005, Ms SQL Server 2008, Ms SQL Server 2012

|
|
 |
 |
 |
 |
Date :
2014-01-08 11:53:27 |
By :
wutSukyarerk |
View :
707 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ฐานข้อมูล ต้องสัมพันธ์กับ input ที่ต้องการเก็บ 
|
 |
 |
 |
 |
Date :
2014-01-08 12:00:33 |
By :
mangkunzo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|