21,887
社区成员
发帖
与我相关
我的任务
分享
<?php
if ( isset($_GET['action']) && $_GET['action'] == "save" )
{
include_once('conn.php'); //连接数据库
include_once('uploadclass.php');//这个文件在下文会给出
$pic=$uploadfile; //第一张图片,已经可以正常上传
$pic2=$uploadfile2; //第二张,上传不了
$sql="insert into product (pic,pic2) values ('$pic','$pic2')";
$result=mysql_query($sql,$conn);
if (!$result)
{
echo mysql_error();
echo $sql;
exit;
}
else
{
echo"<Script>window.alert('congratulations,the product data inserted successful');location.href='index.php'</Script>";
}
mysql_close();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Administrator for upload the product resource</title>
</head>
<body>
<form method="post" action="?action=save" enctype="multipart/form-data" >
Images_1:
<input name="file" type="file" value="Browse" />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<br />
Images_2:
<input name="file2" type="file" value="Browse" />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<p />
<input type="submit" value="upload this resource" name="upload" />
</form>
</body>
</html>
<?php
$uploaddir = "../images/upfiles/";
$type=array("jpg","gif","bmp","jpeg","png");
$patch="aloesky/";
function fileext($filename)
{
return substr(strrchr($filename, '.'), 1);
}
function random($length)
{
$hash = 'CR-';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++)
{
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
$a=strtolower(fileext($_FILES['file']['name']));
if(!in_array(strtolower(fileext($_FILES['file']['name'])),$type))
{
$text=implode(",",$type);
echo "You can only upload the following types of files:",$text,"<br /> <a href='upload_pro.php'>return and try again?click me</a>";
exit;
}
else{
$filename=explode(".",$_FILES['file']['name']);
do
{
$filename[0]=random(10);
$name=implode(".",$filename);
//$name1=$name.".Mcncc";
$uploadfile=$uploaddir.$name;
}
while(file_exists($uploadfile));
if (move_uploaded_file($_FILES['file']['tmp_name'],$uploadfile))
{
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
echo "the Images Upload failed!";
}
else
{
echo "<center>Your file has been uploaded: </center><br><center><img src='$uploadfile' /></center>";
echo "<br><center><a href='upload_pro.php'>Continue to upload</a></center>";
}
}
}
?>
$filename = $_FILES['upload']['name'];//获取来自表单的文件名
$filename = time() . mt_rand(1000, 9999) . '.' . trim(strtolower(substr(strrchr($filename, '.'), 1)));//对文件进行重命名,以免发生重复文件
move_uploaded_file($_FILES['upload']['name'], $filename);//把文件移动到指定的路径