我找到的php上传代码
来源:互联网 发布:多变量优化 编辑:程序博客网 时间:2024/05/20 18:42
<?
require_once "include/define_inc.php"; //全局参数设定
require_once 'include/db_mysql.class.php';//定义
require_once 'include/config.inc.php';//定义
require_once 'include/function.php';//定义
require_once 'include/x.php';//定义
date_default_timezone_set("Etc/GMT-8");
?>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" type="text/css" href="include/css/admin.css" />
<script type="text/javascript">
<!--
var maxWidth=108;
var maxHeight=130;
var fileTypes=["jpg","gif","png"];
var outImage="preview";
var defaultPic="include/images/16.jpg";
var globalPic;
function preview(what, num){
var source=what.value;
var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
globalPic=new Image();
if (i<fileTypes.length) globalPic.src=source;
else {
globalPic.src=defaultPic;
what.outerHTML = what.outerHTML.replace(/value=/w/g,"");
alert("文件类型错误,允许的图片文件后缀是: "+fileTypes.join(", "));
}
setTimeout("applyChanges("+num+")",200);
}
function applyChanges(num){
var field=document.getElementById(outImage + num);
var x=parseInt(globalPic.width);
var y=parseInt(globalPic.height);
if (x>maxWidth) {
y*=maxWidth/x;
x=maxWidth;
}
if (y>maxHeight) {
x*=maxHeight/y;
y=maxHeight;
}
field.style.display=(x<1 || y<1)?"none":"";
field.src=globalPic.src;
field.width=x;
field.height=y;
}
function picdelete(what, num) {
var file = document.getElementById("pic" + num);
var pic = document.getElementById(outImage + num);
file.outerHTML = file.outerHTML.replace(/value=/w/g,"");
pic.src=defaultPic;
pic.width=maxWidth;
pic.height=maxHeight;
}
function submitcheck() {
var subject=document.getElementById("title");
if (subject.value.length < 2 || subject.value.length > 40) {
alert("主题长度不符合要求(2~20个字符)");
subject.focus();
return false;
}
var tlink = document.getElementById("link");
if (tlink.value<1) {
alert("请输入连接地址");
tlink.focus();
return false;
}
}
//-->
</script>
<style type="text/css">
<!--
.STYLE1 {color: #990000}
-->
</style>
<?php
if($_GET['action'] =='upfile'&&is_numeric($tid))
{
$tid=verify_id($tid);
$sql="select picpath,filepath from testdb.maglist where tid={$tid}";
$result=$db->query($sql);
$f=$db->fetch_array($result);
$gettime = explode(' ',microtime());
$string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
$rand .= substr($string,mt_rand(0,strlen($string)-1),1);
$t=date("ymdHis").substr($gettime[0],2,6).$rand;
$target_path=$f['picpath'];
$target_path1=$f['filepath'];
$filesize=$f['filesize'];
if($_FILES['pic1']['size']>0){
$name=explode('.',$_FILES['pic1']['name']);
$target_path = './include/images'.$t.'.'.$name[1];
$tp = array("image/gif","image/pjpeg","image/jpeg","image/jpg");
if(!in_array($_FILES["pic1"]["type"],$tp))
{
echo "<script>alert('上传图片格式不对');history.go(-1);</script>";
exit;
}//END IF
move_uploaded_file($_FILES['pic1']['tmp_name'], $target_path);
unlink($f['picpath']);
$pic="picpath='{$target_path}'";
}
if($_FILES['file1']['size']>0){
$name1=explode('.',$_FILES['file1']['name']);
$target_path1 = './include/images'.$t.'.'.$name1[1];
$tp1 = array("application/octet-stream","application/x-shockwave-flash");
//检查上传文件是否在允许上传的类型
if(!in_array($_FILES["file1"]["type"],$tp1))
{ echo $_FILES["file1"]["type"];
echo "<script>alert('上传文件格式不对');history.go(-1);</script>";
exit;
}
move_uploaded_file($_FILES['file1']['tmp_name'], $target_path1);
unlink($f['filepath']);
$file="filepath='{$target_path1}'";
$filesize=$_FILES['file1']['size'];
}
if($target_path1==NULL||$target_path==NULL){
echo "<script>alert('上传失败');history.go(-1);</script>";}
if(file_exists($target_path)&&file_exists($target_path1)) {
if($_SERVER["OS"]!="Windows_NT"){
@chmod($target_path,0604);
@chmod($target_path1,0604);
}
$a=round($filesize/1048576, 2);
echo $a.'M<br>';
echo $target_path.'<br>';
echo $target_path1.'<br>';
if($sort==1){
$fname="游戏";}
if($sort==2){
$fname="动画";}
if($sort==3){
$fname="漫画";}
if($sort==4){
$fname="动漫中国";}
$t=time();
$sql="update testdb.maglist set fid={$sort},title='{$title}',posttime='{$t}',fname='{$fname}',introduce='{$content}',picpath='{$target_path}',filepath='{$target_path1}',abs='{$abs}',keyname='{$keyname}',filesize='{$filesize}' where tid={$tid}";
$db->query($sql);
echo "<script>alert('修改成功');window.close();</script>";
} else {
echo "<script>alert('上传失败');history.go(-1);</script>";
}
exit;
}
else if(is_numeric($tid)){
$tid=verify_id($tid);
$sql="select introduce,title,abs,keyname from testdb.maglist where tid={$tid}";
$s=$db->query($sql);
$fs=$db->fetch_array($s);
$con=$fs['introduce'];
$con=str_replace("/"",""",$con);
$title=$fs['title'];
$abs=$fs['abs'];
$keyname=$fs['keyname'];
}
?>
<title>修改杂志</title><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="STYLE1" style=" border-top:1px solid #d6d6d6;border-left:1px solid #d6d6d6;border-right:1px solid #d6d6d6;border-bottom:1px solid #d6d6d6;">
<tr>
<td width="100%" height="32" colspan="6" background="images/bg_list.gif" class="editiontext"> 杂志分类修改 <a href="http://www.webacg.com/indexkl.php" target="_blank"></a></td>
</tr>
</table>
<form action="?action=upfile" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="javascript:KindSubmit();">
<table width="100%" border="0" cellpadding="5" cellspacing="5" style="border:1px solid #f5f5f5">
<tr bgcolor="#FFFFFF">
<td height="172" colspan="3" valign="top" >
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="17%" align="center" class="calendar_default">选择类别:</td>
<td width="66%" align="center"><label>
<select name="sort" id="sort">
<option value="1" selected="selected"
>
游戏</option>
<option value="2"
>
动画</option>
<option value="3"
>
漫画</option>
<option value="4"
>动漫中国</option>
</select>
</label></td>
<td width="17%" rowspan="6" align="center"><img alt="图片预览" id="preview1" src="include/images/16.jpg" width="108" height="130" class="avatar" onClick="picdelete(this, 1)" style="border:1px solid #FFCC00"></td>
</tr>
<tr>
<td align="center" class="calendar_default">杂志名称:</td>
<td align="center"><label>
<input name="title" type="text" id="title" size="50" maxlength="28" value="<?=$title?>" />
(少于20个字)
</label></td>
</tr>
<tr>
<td height="29" align="center" class="calendar_default">杂志文件:</td>
<td align="center"><label>
<input type="file" name="file1" id="file1" size="50" />
</label>
(文件类型exe或swf)</td>
</tr>
<tr>
<td align="center" class="calendar_default">杂志摘要:</td>
<td align="center"><label>
<input name="abs" type="text" size="50" value="<?=$abs?>" />
(少于20个字)
</label></td>
</tr>
<tr>
<td align="center" class="calendar_default">封面:分辨率(200*292)</td>
<td align="center"><label>
<input type="file" name="pic1" id="pic1" onchange="preview(this,1)" size="50" />
</label><input type="hidden" name="tid" value="<?=$tid?>" /></td>
</tr>
<tr>
<td height="29" align="center" class="calendar_default">关键字:用,号隔开</td>
<td align="center"><textarea name="keyname" cols="52" ><?=$keyname?></textarea></td>
</tr>
<tr>
<td height="29" align="center" class="calendar_default">内容简介</td>
<td align="center">
</td>
</tr>
</table>
</table>
<table width="99%" border="0" align="center" cellpadding="5" cellspacing="0" style="border:1px solid #BBDCF1;">
<tr>
<td height="35" align="middle" bgcolor="#FFFFFF" class="calendar_default"> <input type="hidden" name="content" value="<?=$con?>">
<script type="text/javascript" src="kindeditor/KindEditor.js"></script>
<script type="text/javascript">
var editor = new KindEditor("editor");
editor.hiddenName = "content";
editor.skinPath = "./kindeditor/skins/default/";
editor.iconPath = "./kindeditor/icons/";
editor.imageAttachPath = "./kindeditor/attached/";
editor.imageUploadCgi = "./kindeditor/upload_cgi/upload.php";
editor.cssPath = "./common.css";
editor.editorType = "full";
editor.editorWidth = "980px";
editor.editorHeight = "400px";
editor.show();
function KindSubmit() {
editor.data();
}
</script></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="5" cellspacing="0" style="border:1px solid #BBDCF1;">
<tr><td height="29" align="center" bgcolor="#FFFFFF" class="calendar_default"> </td>
<td height="35" valign="middle" bgcolor="#FFFFFF" class="calendar_default"><input type="submit" name="Submit" value="提交" />
<input type="reset" name="Submit2" value="重置" /></td>
</tr>
</table>
</form>
<table width="99%" border="0" align="center" cellpadding="5" cellspacing="0" style="border:1px solid #BBDCF1;">
<tr>
<td height="35" align="middle" bgcolor="#FFFFFF" class="calendar_default"> 杂志分为:动漫中国,游戏,动画,漫画</td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #BBDCF1;">
<tr>
<td height="35" valign="middle" bgcolor="#FFFFFF" class="calendar_default"> </td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #BBDCF1;">
<tr>
<td height="35" valign="middle" bgcolor="#FFFFFF" class="calendar_default"> </td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #BBDCF1;">
<tr>
<td height="35" valign="middle" bgcolor="#FFFFFF" class="calendar_default"> </td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #BBDCF1;">
<tr>
<td height="35" valign="middle" bgcolor="#FFFFFF" class="calendar_default"> </td>
</tr>
</table>
- 我找到的php上传代码
- php 上传视频的代码,
- PHP上传的实例代码
- 博客新家。找到可以上传附件的博客。方便上传代码。
- 简单的PHP文件上传代码
- php 实现简单的图片上传代码
- php实现文件上传的代码
- 检测PHP空间上传状态的代码
- php上传类的实现代码
- PHP最简单的上传代码
- 简单的PHP文件上传代码
- PHP一段上传文件的代码
- 防止上传webshell的PHP代码
- 我找到我想要的
- php文件上传最简单的上传代码示例
- PHP图片上传代码
- PHP图片上传代码
- PHP文件上传代码
- 我们还能吃什么? 由三鹿奶粉想到的
- 影响人一生的小故事
- 信息安全技术
- Python基础篇1
- petshop4.0 ( 三) 数据库访问消息处理
- 我找到的php上传代码
- 解决回车刷新页面问题
- php分页代码
- Delphi和C++数据类型对照表
- AIX下如何正确卸载DB2
- 用Xml2OleDb将XML文件插入到数据库
- Compare files' differ and backup
- 开源软件SOA解决方案对企业的三大好处
- 截屏的代码(JAVA)