[求助]大家帮看下这段PHP代码:
小第是第一次用PHP程序,想修改一下,实在是一点都不懂,还望各位指教一下,谢谢!<center>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!is_uploaded_file($_FILES["upfile"]))
//是否存在文件
{
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;
$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;
echo " <font color=red>已经成功上传</font><br>文件名: <font color=blue>".$destination_folder.$fname."</font><br>";
echo " 宽度:".$image_size;
echo " 长度:".$image_size;
if($watermark==1)
{
$iinfo=getimagesize($destination,$iinfo);
$nimage=imagecreatetruecolor($image_size,$image_size);
$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)
{
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,$image_size);
imagefilledrectangle($nimage,1,$image_size-15,80,$image_size,$white);
switch($watertype)
{
case 1://加水印字符串
imagestring($nimage,2,3,$image_size-15,$waterstring,$black);
break;
case 2://加水印图片
$simage1 =imagecreatefromgif("xplore.gif");
imagecopy($nimage,$simage1,0,0,0,0,85,15);
imagedestroy($simage1);
break;
}
switch ($iinfo)
{
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*$imgpreviewsize)." height=".($image_size*$imgpreviewsize);
echo " alt=\"图片预览:\r文件名:".$destination."\r上传时间:\" border='0'></a>";
}
}
?>
</center>
这段代码是:
<script >
parent.input.message.value+='<%=filepath%>'
location.replace('*****/up.php')
</script>
这段代码我在ASP里会用, 可是到了PHP里就一点也搞不明白了!
上面的是图片上传程序,现在论坛与附件不是在一个空间,我现在想点击上传附件后让程序取得图片路径后,把路径地址返回到帖子内容里,也就是类似这样的:
http://www.***.com/love/gif
谢谢! 不懂 更不懂。 下面是引用jxp于2005-02-11 19:45发表的:
更不懂。
[求助]大家帮看下这段PHP代码:
小第是第一次用PHP程序,想修改一下,实在是一点都不懂,还望各位指教一下,谢谢!<center>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!is_uploaded_file($_FILES["upfile"]))
//是否存在文件
{
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;
$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;
echo " <font color=red>已经成功上传</font><br>文件名: <font color=blue>".$destination_folder.$fname."</font><br>";
echo " 宽度:".$image_size;
echo " 长度:".$image_size;
if($watermark==1)
{
$iinfo=getimagesize($destination,$iinfo);
$nimage=imagecreatetruecolor($image_size,$image_size);
$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)
{
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,$image_size);
imagefilledrectangle($nimage,1,$image_size-15,80,$image_size,$white);
switch($watertype)
{
case 1://加水印字符串
imagestring($nimage,2,3,$image_size-15,$waterstring,$black);
break;
case 2://加水印图片
$simage1 =imagecreatefromgif("xplore.gif");
imagecopy($nimage,$simage1,0,0,0,0,85,15);
imagedestroy($simage1);
break;
}
switch ($iinfo)
{
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*$imgpreviewsize)." height=".($image_size*$imgpreviewsize);
echo " alt=\"图片预览:\r文件名:".$destination."\r上传时间:\" border='0'></a>";
}
}
?>
</center>
这段代码是:
<script >
parent.input.message.value+='<%=filepath%>'
location.replace('*****/up.php')
</script>
这段代码我在ASP里会用, 可是到了PHP里就一点也搞不明白了!
上面的是图片上传程序,现在论坛与附件不是在一个空间,我现在想点击上传附件后让程序取得图片路径后,把路径地址返回到帖子内容里,也就是类似这样的:
http://www.***.com/love/gif
谢谢!
页:
[1]