简单php 图片上传代码 php 上传图片代
$zpname=addslashes(isset($_POST['zpname'])?$_POST['zpname']:'');
$zpurl=isset($_POST['zpurl'])?$_POST['zpurl']:'';
$zpsay=addslashes(isset($_POST['zpsay'])?$_POST['zpsay']:'');
$blueidea=isset($_POST['blueidea'])?$_POST['blueidea']:'';
$up_path="../zp/";
$up_size=100000;
$up_name=md5(date("Y:m:d H:i:s"));
$up_type=$_FILES['file']['type'];
$up_exten="start:image/gifimage/pjpegimage/x-png";
echo $up_type;
echo(strrpos($up_exten,$up_type));
//exit();
//=$up_wh['mime'];
$up_sava='';
//echo($_FILES['file']['size']);
//echo($_FILES['file']['type']);
//exit();
if($zpname=="" || $zpname>50){
echo("<script>alert('作品名称不能为空或大于50个字符!');history.back();</script>");
exit();
}
if(!ereg("^(http|https|ftp)\://((([a-zA-Z0-9\-]+\.){1,}[a-zA-Z]{2,4})|(localhost))(:[0-9]+){0,1}(/[a-zA-Z0-9\-\_\,\./\+&%\$#\=~]+)*$",$zpurl)){
echo("<script>alert('作品地址URL不合法!');history.back();</script>");
exit();
}
if($zpsay=="" || $zpsay>500){
echo("<script>alert('作品简介不能为空或大于500个字符!');history.back();</script>");
exit();
}
if(strrpos($up_exten,'image/x-png')){
$up_sava=$up_path.$up_name.'.png';
}
if(strrpos($up_exten,'image/pjpeg')){
$up_sava=$up_path.$up_name.'.jpg';
}
if(strrpos($up_exten,'image/gif')){
$up_sava=$up_path.$up_name.'.gif';
}
if($up_sava==''){
echo("<script>alert('对不起,你上传的类型不对,只允许上传 .gif .jpg .png');history.back();</script>");
exit();
}
if($_FILES['file']['size']>$up_size){
echo("<script>alert('上传文件不能大于100K');history.back();</script>");
exit();
}
/*print_r($up_wh['mime']);
exit();
if($up_wh[0]>300 || $up_wh>400 || $up_wh[0]
echo("<script>alert('图片宽度93-300之间,高度400-63之间');history.back();</script>");exit();
}
*/
if(move_uploaded_file($_FILES['file']['tmp_name'],$up_sava)){
up_insert($zpname,$zpurl,$zpsay,$blueidea,$up_name.'.gif');
echo("<script>alert('上传成功');location='".$_SERVER['HTTP_REFERER']."';</script>");
}else{
echo("<script>alert('未知错误');history.back();</script>");
}
function up_insert($zpname,$zpurl,$zpsay,$blueidea,$up_filename){
$up_sava="zp/".$up_filename;
connect();
mysql_query($sql) or die('Insert into data fail:'.mysql_error());
}
?>