|
 |
|
อยากให้สคริปอัพโหลด สามารถตรวจสอบนามสกุลไฟล์ได้ ทำงัยครับเพิ่มตรงใหน |
|
 |
|
|
 |
 |
|
พี่ ๆ ครับผมอยากให้โค้ดข่างล่างนี้มัน
1.ใช้ได้เฉพาะนามสกุล gif jpeg png ครับกลัว User อัพไฟล์มั่วอ่ะครับ
2.แล้วก็ถ้าอยากเปลี่ยนชื่อไฟล์ให้ตรงกับวันที่ทำงัยอ่ะครับ เช่น 151011XX.jpg อย่างงี้ครับ
พี่ ๆ ใหนเทพช่วยผมที
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP Upload Resize to MySQL</title>
</head>
<body>
<?
if(trim($_FILES["fileUpload"]["tmp_name"]) != "")
{
$images = $_FILES["pic_first"]["tmp_name"];
$new_images = "mhk_".$_FILES["pic_first"]["name"];
copy($_FILES["pic_first"]["tmp_name"],"../../pic/pic/".$_FILES["pic_first"]["name"]);
$width=130; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
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,"../../pic/pic/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin)
echo "Resize Successful.<br>";
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "INSERT INTO files ";
$strSQL .="(Thumbnails,FilesName) VALUES ('".$new_images."','".$_FILES["fileUpload"]["name"]."')";
$objQuery = mysql_query($strSQL);
}
?>
<a href="phpUploadResizeToMySQL3.php">View files</a>
</body>
</html>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2011-10-11 13:19:04 |
By :
Jinns |
View :
745 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
explode ออกสิครับเพราะยังไงก่อนนามสกุลไฟล์ก็คือสัญลักษณ์ "." อยู่แล้ว จากนั้นค่อยนำไปเช็ค if อีกทีครับ หลักการนะ
|
 |
 |
 |
 |
Date :
2011-10-11 13:21:15 |
By :
ppanchai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|