<?php
for($i=0;$i<count($_FILES["filUpload"]["name"]);$i++)
{
if($_FILES["filUpload"]["name"][$i] != "")
{
$filUpload=$_FILES['filUpload']['tmp_name'][$i];
$filUpload_name=$_FILES['filUpload']['name'][$i];
$filUpload_size=$_FILES['filUpload']['size'][$i];
$filUpload_type=$_FILES['filUpload']['type'][$i];
$ext = strtolower(end(explode('.', $filUpload_name)));
if ($ext == "jpg" or $ext == "jpeg" or $ext =="png" or $ext=="gif") {
// หา id_slider ที่มากที่สุดของ slider
$sql="select max(id_slider) from slider";
$result=mysql_db_query($dbname,$sql);
$r=mysql_fetch_array($result);
$id_max=$r[0];
$filename=$id_max.".".$ext;
copy($filUpload,"../images/slider/$filename");
if ($ext =="jpg" or $ext =="jpeg") {
$ori_img = imagecreatefromjpeg($filename);
} else if ($ext =="png") {
$ori_img = imagecreatefrompng($filename);
} else if ($ext =="gif") {
$ori_img = imagecreatefromgif($filename);
}
$ori_size = getimagesize($filename);
$ori_w = $ori_size[0];
$ori_h = $ori_size[1];
$new_w = 480;
$new_h = 220;
$new_img= imagecreatetruecolor($new_w, $new_h);
imagecopyresized($new_img,$ori_img,0,0,0,0,$new_w, $new_h,$ori_w,$ori_h);
if ($ext =="jpg" or $ext =="jpeg") {
imagejpeg($new_img,"../images/slider/$filename");
} else if ($ext =="png") {
imagepng($new_img,"../images/slider/$filename");
} else if ($ext =="gif") {
imagegif($new_img,"../images/slider/$filename");
}
imagedestroy($ori_img);
imagedestroy($new_img);
$sql="insert into slider value('','$filename')";
$result=mysql_db_query($dbname,$sql);
}
}
}
echo "<script>alert(' เพิ่มข้อมูลเรียบร้อยแล้ว ');</script>";
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0.1;URL=slider.php\">"; exit();
?>
Error ที่แดสง
Warning: imagecreatefromjpeg(20.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in C:\AppServ\www\dsi\administrator\slider_upload.php on line 38
Warning: getimagesize(20.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\AppServ\www\dsi\administrator\slider_upload.php on line 44
Warning: imagecopyresized(): supplied argument is not a valid Image resource in C:\AppServ\www\dsi\administrator\slider_upload.php on line 52
Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\AppServ\www\dsi\administrator\slider_upload.php on line 62