picture.php
<form action="PictureBeGet.php" method="post" name="form1" id="form1" ENCTYPE="multipart/form-data" >
<input type="file" name="myfile" size="35">
<input type="submit" value="送出">
picturebeget.php
<?php session_start(); ?>
<?php
$password=$_SESSION["password"];
$numberforsession=$_SESSION["number"];
/*這邊是在紀錄網頁使用者登入的IP和密碼,Picture頁面那邊沒有列出;*/
$i=$_GET["i"];
$j=$_GET["j"];
$k=$_GET["k"];
$l=$_GET["l"];
/*這是判定javscript傳過來的Picture頁面有四個按鈕,要判定按的是哪一個按鈕,i是刪除圖片按鈕,j是履歷預覽按鈕,k是送出履歷應徵按鈕,l是前往作品附件上傳按鈕。Picture頁面那邊沒有列出;*/
$introduceyourself=$_POST["introduceyourself"];
/*這是自傳上傳,Picture頁面那邊沒有列出;*/
$Picture =$_FILES["myfile"];
/*Picture頁面傳來的照片擋*/
$tmpname=$Picture["tmp_name"];
/*照片擋暫存在電腦的暫存名稱。*/
$name=$Picture["name"];
/*照片擋的真實名稱*/
$type=$Picture["type"];
/*照片擋的類別,圖檔的話會顯示image/pjpeg.....*/
$error=$Picture["error"];
/*照片擋的錯誤狀態*/
require_once("../../Company_connect.php");
/*引入連線mysql資料庫的密碼帳號連線*/
if($i=="1"){
/*如果使用者有按下刪除照片按鈕的話,$i=="1",則進行把資料庫中的此筆資料改為picture欄位沒有上傳照片的路徑*/
$sql="update picture set picture='' where number='$numberforsession'";
$result=mysql_query($sql,$link);
if($result==true)
echo "<script>alert('刪除成功!!');location.href='Picture.php'</script>";
}else{
if($name!==""){
/*$name!==""代表Picture頁面使用者有上傳圖片*/
$fileName=date("U");/*用date("U")當檔名是要避免其他使用者上傳依樣檔名的檔案會被覆蓋,或是上傳中文檔名會無法儲存的問題。*/
$image_pathFS="../../LittlePictures/"; /*產生縮圖要放的相對路徑*/
$image_path="../../BigPictures/"; /*使用者上傳的大圖放的相對路徑*/
if ($error==4 && $name==""){
$pIMb="";$pIMs="";
}else{
if($type=="image/jpeg" || $type=="image/pjpeg")
$fileExt="jpg";
else if($type=="image/gif" || $type=="image/pgif")
$fileExt="gif";
else{
echo "<script>alert('您的檔案並非jpeg 或 gif 檔。');location.href='Picture.php';</script>";
exit();
}
}
$pIMb=$fileName."_b.".$fileExt; /*用現在的時間+_b.+副檔名來取代使用者上傳的大圖檔名。*/
$pIMs=$fileName."_s.".$fileExt; /*用現在的時間+_s.+副檔名來為縮圖命名*/
$real=$image_pathFS.$pIMs; /*這裡是要存進去資料庫的圖片路徑,ex:../../LittlePicture/abcde.jpg*/
$res=copy($tmpname,$image_path.$pIMb); /*先把使用者上傳的圖片複製到大圖放置的地方*/
chmod($image_path.$pIMb,0777); /*這是為了在linux的環境下,要產生縮圖時檔案要是能編輯的狀態,因此把大圖的權限開為777(全開)*/
function getResizePercent($source_w, $source_h, $inside_w, $inside_h)
{
if ($source_w < $inside_w && $source_h < $inside_h) {
return 1; // Percent = 1, 如果都比預計縮圖的小就不用縮
}
$w_percent = $inside_w / $source_w;
$h_percent = $inside_h / $source_h;
return ($w_percent > $h_percent) ? $h_percent : $w_percent;
}
function ImageResize($from_filename, $save_filename, $in_width=110, $in_height=140, $quality=100)
{
$allow_format = array('jpeg','gif');
$sub_name = $t = '';
/* Get new dimensions*/
$img_info = getimagesize($from_filename); /*抓取大圖的資訊*/
$width = $img_info['0'];
$height = $img_info['1'];
$imgtype = $img_info['2'];
$imgtag = $img_info['3'];
$bits = $img_info['bits'];
$channels = $img_info['channels'];
$mime = $img_info['mime'];
list($t, $sub_name) = split('/', $mime); /*這是要把mime的內容用"/"切開,/的後面是副檔名(jpg,gif)*/
if ($sub_name == 'jpg') {
$sub_name = 'jpeg';
}else if($sub_name =='gif')
$sub_name='gif';
if (!in_array($sub_name, $allow_format)) {
return false;
}
// 取得縮在此範圍內的比例
$percent = getResizePercent($width, $height, $in_width, $in_height);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_new = imagecreatetruecolor($new_width, $new_height);
// $function_name: set function name
// => imagecreatefromjpeg, imagecreatefrompng, imagecreatefromgif
/*
// $sub_name = jpeg,gif
$function_name = 'imagecreatefrom'.$sub_name;
$image = $function_name($filename); //$image = imagecreatefromjpeg($filename);
*/
if($sub_name=="jpeg"){
$image = imagecreatefromjpeg($from_filename);
imagecopyresampled($image_new, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
return imagejpeg($image_new, $save_filename, $quality);
}else if($sub_name=="gif"){
$image= imagecreatefromgif($from_filename);
imagecopyresampled($image_new, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
return imagegif($image_new, $save_filename, $quality);
}
}
$x=$image_path.$pIMb;
$y=$image_pathFS.$pIMs;
ImageResize($x,$y,$a,$b,$c);
//$pic_size=GetImageSize($image_path.$pIMb,&$info);取得原圖資訊
/*$im = imagecreatefromjpeg($tmp_name);
$im2 = imagecreatetruecolor ($dst_w, $dst_h);
imagecopyresampled($im2, $im, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
header('Content-type: image/jpeg');
header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
imagejpeg($im2);
imagedestroy($im);
imagedestroy($im2);*/
/**
* 抓取要縮圖的比例
* $source_w : 來源圖片寬度
* $source_h : 來源圖片高度
* $inside_w : 縮圖預定寬度
* $inside_h : 縮圖預定高度
* Test:
* $v = (getResizePercent(1024, 768, 400, 300));
* echo 1024 * $v . "\n";
* echo 768 * $v . "\n";
*/
/*if ($pic_size[0] > 120 || $pic_size[1] > 120) {//判斷圖檔大小及設定縮圖大小
$cmd="www/0426company/LittleUpLoadPictures/";
$cmd .=$image_path.$pIMb;
$cmd .=" -resize 120x120\> ";
$cmd .=$image_path.$pIMs;
exec($cmd);//產生縮圖,上面的 -resize 120x120 是取圖的長邊最大為120
}else{
copy($image_path.$pIMb,$image_pathFS.$pIMs);
}*/
$sql2="select picture from picture where number='$numberforsession'";
$result23=mysql_query($sql2,$link);
$rows=mysql_num_rows($result23);
if($rows==0)
$sql="insert into picture values('$numberforsession','$password','$real','$introduceyourself')";
else if($rows==1)
$sql="update picture set picture='$real',introduceyourself='$introduceyourself' where number='$numberforsession'";
$sql1="update allinformation set introduceyourself ='yes' where number='$numberforsession'";
$sql123=mysql_query($sql,$link);
$sql2=mysql_query($sql1,$link);
}else if($name==""){
$sql2="select picture from picture where number='$numberforsession'";
$result23=mysql_query($sql2,$link);
$rows=mysql_num_rows($result23);
if($rows==0)
$sql="insert into picture values('$numberforsession','$password','','$introduceyourself')";
else if($rows==1)
$sql="update picture set introduceyourself='$introduceyourself' where number='$numberforsession'";
$sql1="update allinformation set introduceyourself ='yes' where number='$numberforsession'";
$sql123=mysql_query($sql,$link);
$sql2=mysql_query($sql1,$link);
}
if($sql123==true && $sql2==true){
if(!$j=="")
echo "<script>alert('上傳成功');location.href='Picture.php'</script>";
if(!$k=="")
echo "<script>alert('上傳成功');location.href='Picture.php'</script>";
if(!$l=="")
echo "<script>location.href='Picture.php'</script>";
}else
echo "<script>alert('上傳失敗');location.href='Picture.php'</script>";
}
?>
</body>
</html>
請先 登入 以發表留言。