复制代码 代码如下:
header("content-Type: text/html; charset=gb2312");
$uptypes=array('image/jpg', //上传文件类型列表
'image/jpeg',
'image/png',
'image/pjpeg',
'image/gif',
'image/bmp',
'application/x-shockwave-flash',
'image/x-png',
'application/msword',
'audio/x-ms-wma',
'audio/mp3',
'application/vnd.rn-realmedia',
'application/x-zip-compressed',
'application/octet-stream');
$max_file_size=10000000; //上传文件大小限制, 单位BYTE
$path_parts=pathinfo($_SERVER['PHP_SELF']); //取得当前路径
$destinati href="http://www.yinao.tk/ico.ico" >
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!is_uploaded_file($_FILES["upfile"][tmp_name]))
//是否存在文件
{
echo "文件不存在!";
exit;
}
$file = $_FILES["upfile"];
if($max_file_size //检查文件大小
{
echo "文件太大!";
exit;
}
if(!in_array($file["type"], $uptypes))
//检查文件类型
{
echo "不能上传此类型文件!";
exit;
}
if(!file_exists($destination_folder))
mkdir($destination_folder);
$filename=$file["tmp_name"];
$image_size = getimagesize($filename);
$pinfo=pathinfo($file["name"]);
$ftype=$pinfo[extension];
$destination = $destination_folder.time().".".$ftype;
if (file_exists($destination) && $overwrite != true)
{
echo "同名文件已经存在了!";
exit;
}
if(!move_uploaded_file ($filename, $destination))
{
echo "移动文件出错!";
exit;
}
$pinfo=pathinfo($destination);
$fname=$pinfo[basename];
echo " 成功上传,鼠标移动到地址栏自动复制
";
echo " 寬度:".$image_size[0];
echo " 長度:".$image_size[1];
if($watermark= =1)
$iinfo=getimagesize($destination,$iinfo);
$nimage=imagecreatetruecolor($image_size[0],$image_size[1]);
$white=imagecolorallocate($nimage,255,2555,255,0, nimage,255,2555,255); 0);
$red=imagecolorallocate($nimage,255,0,0);
imagefill($nimage,0,0,$white);
案例1:
$simage =imagecreatefromgif($destination); =imagecreatefromjpeg($destination);
案例3:
$simage =imagecreatefrompng( $destination);
$simage =imagecreatefromwbmp($destination); default:
die("'red' ! image_size [1]-15,80,$image_size[1],$white);
switch($watertype)
{
case 1: //加水印字串
imagestring($nimage,2,3,$image_size[ 1) ]-15,$waterstring,$black);
break;
case 2: //加水印圖片
$simage1 = imagecreatefromgif("xplore.gif");
imagecopy($nimage,$simage1,0,0 ,0,0,85,15);
imagedestroy($simage1);
休息;
}
switch ($iinfo[2])
{
情況1:
//imagegif($nimage, $destination);
imagejpeg($nimage, $destination);
休息;
情況2:
imagejpeg($nimage, $destination);
休息;
情況 3:
imagepng($nimage, $destination);
休息;
案例6:
imagewbmp($nimage, $destination);
//imagejpeg($nimage, $destination);
休息;
}
//覆蓋原始上傳檔案
imagedestroy($nimage);
imagedestroy($simage);
}
if($imgpreview==1)
{
echo "
圖片預覽:
";
echo "echo " alt="圖片上傳 php圖片上傳儲存原始碼並且可以預覽".$fname."r上傳時間:".date('m/d/Y h:i')."" border='0'>”;
}
}
?
以上就介紹了圖片上傳 php圖片上傳儲存原始碼並且可以預覽,包括了圖片上傳方面的內容,希望對PHP教學有興趣的朋友有所幫助。