|
楼主 |
发表于 2005 年 2 月 11 日 19:10:51
|
显示全部楼层
[求助]大家帮看下这段PHP代码:
小第是第一次用PHP程序,想修改一下,实在是一点都不懂,还望各位指教一下,谢谢!
- <center>
- <?php
- if ($_SERVER['REQUEST_METHOD'] == 'POST')
- {
- if (!is_uploaded_file($_FILES["upfile"][tmp_name]))
- //是否存在文件
- {
- echo "<font color='red'>文件不存在!</font>";
- exit;
- }
- $file = $_FILES["upfile"];
- if($max_file_size < $file["size"])
- //检查文件大小
- {
- echo "<font color='red'>文件太大!</font>";
- exit;
- }
- if(!in_array($file["type"], $uptypes))
- //检查文件类型
- {
- echo "<font color='red'>只能上传图像文件或Flash!</font>";
- 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 "<font color='red'>同名文件已经存在了!</a>";
- exit;
- }
-
- if(!move_uploaded_file ($filename, $destination))
- {
- echo "<font color='red'>移动文件出错!</a>";
- exit;
- }
- -----------------------------大家看下面这里,我想在此插入一段script代码----------------------------
- $pinfo=pathinfo($destination);
- $fname=$pinfo[basename];
- echo " <font color=red>已经成功上传</font><br>文件名: <font color=blue>".$destination_folder.$fname."</font><br>";
- 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,255,255);
- $black=imagecolorallocate($nimage,0,0,0);
- $red=imagecolorallocate($nimage,255,0,0);
- imagefill($nimage,0,0,$white);
- switch ($iinfo[2])
- {
- case 1:
- $simage =imagecreatefromgif($destination);
- break;
- case 2:
- $simage =imagecreatefromjpeg($destination);
- break;
- case 3:
- $simage =imagecreatefrompng($destination);
- break;
- case 6:
- $simage =imagecreatefromwbmp($destination);
- break;
- default:
- die("<font color='red'>不能上传此类型文件!</a>");
- exit;
- }
-
- imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]);
- imagefilledrectangle($nimage,1,$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);
- break;
- }
-
- switch ($iinfo[2])
- {
- case 1:
- //imagegif($nimage, $destination);
- imagejpeg($nimage, $destination);
- break;
- case 2:
- imagejpeg($nimage, $destination);
- break;
- case 3:
- imagepng($nimage, $destination);
- break;
- case 6:
- imagewbmp($nimage, $destination);
- //imagejpeg($nimage, $destination);
- break;
- }
-
- //覆盖原上传文件
- imagedestroy($nimage);
- imagedestroy($simage);
- }
- if($imgpreview==1)
- {
- echo "<br>图片预览:<br>";
- echo "<a href=\"".$destination."\" target='_blank'><img src=\"".$destination."\" width=".($image_size[0]*$imgpreviewsize)." height=".($image_size[1]*$imgpreviewsize);
- echo " alt=\"图片预览:\r文件名:".$destination."\r上传时间:\" border='0'></a>";
- }
- }
- ?>
- </center>
复制代码
这段代码是:
<script >
parent.input.message.value+=''
location.replace('*****/up.php')
</script>
这段代码我在ASP里会用, 可是到了PHP里就一点也搞不明白了!
上面的是图片上传程序,现在论坛与附件不是在一个空间,我现在想点击上传附件后让程序取得图片路径后,把路径地址返回到帖子内容里,也就是类似这样的:
- [img]http://www.***.com/love/gif[/img]
复制代码
谢谢! |
|