|
|
|
สอบถามเรื่องการย่อรูปและการใส่ข้อความลงที่ รูปโดยใช้ array หน่อยครับ |
|
|
|
|
|
|
|
ผมได้ ส่งข้อมูลรูปภาพมาเป็น array แบบ Code (PHP)
(move_uploaded_file($_FILES["photo"]["tmp_name"][$i],"images_large/".$_FILES["photo"]["name"][$i]))
ก็ใช้งานได้ปกติ แต่อยากเพิ่ม ให้ย่อรูปได้ด้วย มีโค๊ด
Code (PHP)
$h2=30;
$images = $_FILES["photo"]["tmp_name"];
$new_images = $_FILES["photo"]["name"];
copy($photo,"images_large1/$filename");
//copy($_FILES["photo"]["tmp_name"],"MyResize/".$_FILES["photo"]["name"]);
$width=800; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
$images_orig = ImageCreateFromJPEG($images);
$light=ImageColorAllocate($images_orig,230,230,230);
$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);
ImageString($images_fin,5,5,$h2-20,"www.ฟฟฟฟ.com",$light);
ImageJPEG($images_fin,"images_large1/".$filename);
//ImageJPEG($images_fin,"images_large/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
file ที่ เป็น array แทรกตรงไหน
Code (PHP)
<?
// นับจำนวน array ที่ส่งมา
//echo count($_FILES["photo"]["name"]);
$photo=$_FILES['photo']['tmp_name'];
$photo_name=$_FILES['photo']['name'];
$photo_size=$_FILES['photo']['size'];
$photo_type=$_FILES['photo']['type'];
$detail=$_POST['detail'];
$id_title=$_POST['id_title'];
//echo "$id_title";
include "connect.php";
for($i=0;$i<count($_FILES["photo"]["name"]);$i++)
{
if($_FILES["photo"]["name"][$i] != "")
{
if(move_uploaded_file($_FILES["photo"]["tmp_name"][$i],"images_large/".$_FILES["photo"]["name"][$i]))
{
$sql="insert into tb_photo ";
$sql.="(name_photo,ref_title) VALUES ('".$_FILES["photo"]["name"][$i]."','".$_POST["id_title"]."')";
mysql_db_query($dbname,$sql);
}
}
}
echo "<H3>Upload เสร็จเรียบร้อย</H3>";
echo "<A HREF='admin_photo.php?id_title=$id_title'> ย้อนกลับ </A>";
//echo "<meta http-equiv=refresh content=2;URL='admin_photo.php?id_title=$id_title'>";
?>
<!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=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-image: url(pic1/bg2.jpg);
}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body>
</body>
</html>
อยากจะทราบว่า ผมต้องเปลี่ยน code ใหม่อย่างไงบ้าง เพื่อให้ ให้เหมือนกัน
Tag : PHP
|
|
|
|
|
|
Date :
2015-03-28 20:24:46 |
By :
chayaphol |
View :
714 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตัวอย่างครับ
Code (PHP)
<?php
for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++)
{
if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"][$i];
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"][$i];
copy($_FILES["fileUpload"]["tmp_name"][$i],"MyResize/".$_FILES["fileUpload"]["name"][$i]);
$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
$images_orig = ImageCreateFromJPEG($images);
$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,"MyResize/".$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"][$i]."')";
$objQuery = mysql_query($strSQL);
}
}
?>
PHP Multiple Upload & Multiple Resize to MySQL
|
|
|
|
|
Date :
2015-03-29 07:10:57 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2015-03-30 07:13:43 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|