1. 调用方法例子:
大图路径:<input type="text" name="bigImageURL" id="bigImageURL" value="">
<iframe src="uppic.php?id=bigImageURL" width="600" height="25" frameborder="0" scrolling="no"></iframe>
小图路径:
<input type="text" name="smallImageURL" id="smallImageURL" value="">
<iframe src="uppic.php?id=smallImageURL" width="600" height="25" frameborder="0" scrolling="no"></iframe>
2. uppic.php
<?php
header("Content-Type:text/html;charset=GB2312");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>图片上传</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.3790.4275" name=GENERATOR>
<style type="text/css">
<!--
input{border-width:1px;border:1px solid #bdbcbd;padding:3px 0 3px 5px;}
.inputbut{padding-left:3px;padding-right:2px;border:1px solid #bdbcbd;background:#FFF url(../images/inputbut_bg.gif) left center repeat-x;font-size:12px;height:24px;}
-->
</style>
</HEAD>
<BODY leftmargin=0 topmargin=0 style="font-size:12px">
<?php
$id=$_GET["id"];
//echo "id==".$id;
switch($_GET["action"])
{
case "up":
upmovie($id);
break;
default:
upinput($id);
break;
}
function upinput($id){
?>
<SCRIPT language=javascript>
function check()
{
var strFileName=document.form.strPhoto.value;
if (strFileName=="")
{
alert("请选择要上传的文件");
document.form.strPhoto.focus();
return false;
}
return true;
}
</SCRIPT>
<form action="uppic.php?action=up&id=<?=$id?>" enctype="multipart/form-data" name="form" method="post" onsubmit="if (!check()) return false;">
<input name="strPhoto" type="file" id="strPhoto" size="40">
<input type="submit" name="Submit" value="上 传" class=inputbut />
</form>
</BODY>
<?php
}
function upmovie($id){
global $web_picdir;
$savePath=dirname(__FILE__)."/".$web_picdir;
$str = date('YmdHis');
if($_FILES['strPhoto']['name']!='')
{
$tmp_file=$_FILES['strPhoto']['tmp_name'];
$file_types=explode(".",$_FILES['strPhoto']['name']);
$file_type=$file_types[count($file_types)-1];
if(strtolower($file_type)!="jpg"&strtolower($file_type)!="gif"&strtolower($file_type)!="bmp"&strtolower($file_type)!="png"){
echo "<span style=/"color:red;line-height: 25px;/">格式错误请重新上传<a href=# onclick=history.go(-1);>[返回]</a></span>";
exit;
}
$file_name=$str.".".$file_type;
if(!copy($tmp_file,$savePath.$file_name)){
echo "<span style=/"color:red;line-height: 25px;/">上传错误请重试!!<a href=# onclick=history.go(-1);>[返回]</a></span>";
}else{
//echo "<span style=/"olor:red;line-height: 25px;/">上传成功</span><script>parent.document.getElementById(/"bigImageURL/").value=/"".$file_name."/"</script>";
echo "<span style=/"olor:red;line-height: 25px;/">上传成功</span><script>parent.document.getElementById(/"{$id}/").value=/"".$file_name."/"</script>";
echo "<a href=# onclick=history.go(-1);>,若需要修改,请重新上传</a>";
}
}else{
echo "<span style=/"color:red;line-height: 25px;/">请选择需要上传的文件<a href=# onclick=history.go(-1);>[返回]</a></span>";
}
}
?>
注意: 不同的文本框 需要定义id, iframe url : uppic.php?id=文本框id
分享到:
相关推荐
- **服务器接收请求**:服务器接收到请求后,根据请求路径解析出对应的脚本文件。 - **执行服务器端脚本**:如果请求的是PHP文件,服务器将把文件传给PHP引擎执行。PHP引擎负责解释并执行PHP代码,处理各种逻辑操作...
- **安全的特性赋值**: 使用`safeAttributes()`方法确定哪些属性可以被安全地赋值。 - **触发验证**: 在模型保存前触发验证过程。 - **提取验证错误**: 通过`getErrors()`方法获取验证失败的信息。 - **特性标签**: ...
- **动作(action)**: 控制器内的方法,通常用来处理特定类型的请求。 **4. 过滤器(Filter)** - **定义**: 过滤器是用来执行某些特定任务的类,例如身份验证、权限检查等。 - **用途**: 在执行控制器动作之前...
- 定义表单字段的属性,如类型、长度等。 **6.4 数据主键** - 设置数据表的主键字段。 **6.5 属性查询** - 查询模型对象的属性值。 **6.6 跨库操作** - 支持在一个项目中使用多个数据库。 **6.7 连接数据库** - ...
- **模板赋值**:将数据传递给模板文件。 - **模板渲染**:将模板文件渲染为 HTML 页面。 - **输出替换**:支持在输出内容中进行变量替换。 - **模板定位**:根据文件路径确定模板文件的位置。 - **模板标签**:使用...