❶ php ie8 - 图片上传系统
是安全级别的事情吧
getElementById是通用的,你又没有用getElementByName
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
我的意思是你没有用ByName,应该不会出现这么多的问题.
看你的代码本身都是操作页面,没有出格的地方,IE8应该也不会有特殊的错误,是不是你把IE的安全级别设置的太高导致的
❷ PHP上传图片怎么做
上传类,保存文件名称为 uppoo.php:
<?php
class upphoto{
public $previewsize=0.125 ; //预览图片比例
public $preview=0; //是否生成预览,是为1,否为0
public $datetime; //随机数
public $ph_name; //上传图片文件名
public $ph_tmp_name; //图片临时文件名
public $ph_path="./userimg/"; //上传文件存放路径
public $ph_type; //图片类型
public $ph_size; //图片大小
public $imgsize; //上传图片尺寸,用于判断显示比例
public $al_ph_type=array('image/jpg','image/jpeg','image/png','image/pjpeg','image/gif','image/bmp','image/x-png'); //允许上传图片类型
public $al_ph_size=1000000; //允许上传文件大小
function __construct(){
$this->set_datatime();
}
function set_datatime(){
$this->datetime=date("YmdHis");
}
//获取文件类型
function get_ph_type($phtype){
$this->ph_type=$phtype;
}
//获取文件大小
function get_ph_size($phsize){
$this->ph_size=$phsize."<br>";
}
//获取上传临时文件名
function get_ph_tmpname($tmp_name){
$this->ph_tmp_name=$tmp_name;
$this->imgsize=getimagesize($tmp_name);
}
//获取原文件名
function get_ph_name($phname){
$this->ph_name=$this->ph_path.$this->datetime.strrchr($phname,"."); //strrchr获取文件的点最后一次出现的位置
//$this->ph_name=$this->datetime.strrchr($phname,"."); //strrchr获取文件的点最后一次出现的位置
return $this->ph_name;
}
// 判断上传文件存放目录
function check_path(){
if(!file_exists($this->ph_path)){
mkdir($this->ph_path);
}
}
//判断上传文件是否超过允许大小
function check_size(){
if($this->ph_size>$this->al_ph_size){
$this->showerror("上传图片超过2000KB");
}
}
//判断文件类型
function check_type(){
if(!in_array($this->ph_type,$this->al_ph_type)){
$this->showerror("上传图片类型错误");
}
}
//上传图片
function up_photo(){
if(!move_uploaded_file($this->ph_tmp_name,$this->ph_name)){
$this->showerror("上传文件出错");
}
}
//图片预览
function showphoto(){
if($this->preview==1){
if($this->imgsize[0]>2000){
$this->imgsize[0]=$this->imgsize[0]*$this->previewsize;
$this->imgsize[1]=$this->imgsize[1]*$this->previewsize;
}
echo("<img src=\"{$this->ph_name}\" width=\"{$this->imgsize['0']}\" height=\"{$this->imgsize['1']}\">");
}
}
//错误提示
function showerror($errorstr){
echo "<script language=java script>alert('$errorstr');location='java script:history.go(-1);';</script>";
exit();
}
function save(){
$this->check_path();
$this->check_size();
$this->check_type();
$this->up_photo();
$this->showphoto();
}
}
?>
这里是使用的方法:
<?php
header("Content-Type:text/html; charset=utf-8");
//类的实例化:
include("uppoo.php");//类的文件名是upoop.php
$up=newupphoto;
$submit=$_POST['submit'];
if($submit=="上传"){
$up->get_ph_tmpname($_FILES['photo']['tmp_name']);
$up->get_ph_type($_FILES['photo']['type']);
$up->get_ph_size($_FILES['photo']['size']);
$up->get_ph_name($_FILES['photo']['name']);
$up->save();
}
?>
//上传图片的HTML:
<form action="upphoto.php?action=act" method="post" enctype="multipart/form-data">
图片来源:<input type="file" name="photo">
<input type="submit" name="submit" value="上传">
❸ php图片上传功能(专业的进)
if ($_FILES) {
$valid = Validation::factory($_FILES)
->rule('avatar', 'Upload::valid')
->rule('avatar', 'Upload::not_empty')
->rule('avatar', 'Upload::size', array(':value', Kohana::$config->load('upload.image.size')))
->rule('avatar', 'Upload::type', array(':value', Kohana::$config->load('upload.image.type')));
if ($valid->check()) {
$filename = AUTH::instance()->get_user()->id . '.' . pathinfo($_FILES['avatar']['name'], PATHINFO_EXTENSION); try {
$filepath = Upload::save($_FILES['avatar'], $filename, DOCROOT . 'profile' . DIRECTORY_SEPARATOR . 'avatar');
if ($filepath) {
$image = Image::factory($filepath);
$image->resize(150, 150, Image::INVERSE);
$image->crop(150, 150);
$image->save();
$profile->user_id = $this->mAccount->id;
$profile->avatar = $filename;
$profile->save();
} else {
$errors = array('avatar' => '头像上传失败');
}
} catch (Kohana_Exception $e) {
$errors = array('avatar' => $e->getMessage());
}
} else {
$errors = $valid->errors('upload');
}
}
❹ php中上传图片怎么上传
<?php
class upload{
//可上传的最大文件
public $maxSize = "-1";
// 允许上传的文件后缀
// 留空不作后缀检查
public $allowExts = array();
// 上传文件保存路径
public $savePath = '';
// 错误信息
private $error = '';
// 上传成功的文件信息
private $fileInfo = array() ;
public function __construct($maxSize="",$savePath = '',$allowExts = array()){
if(!empty($maxSize) && is_numeric($maxSize)) {
$this->maxSize = $maxSize;
}
$this->savePath = $savePath;
if(!is_array($allowExts)){
$allowExts = array($allowExts);
}
$this->allowExts = $allowExts;
}
//文件上传
public function save($file){
$this->fileInfo["success"] = "No";
if(empty($file["name"])){
$this->error = "无上传文件";
return false;
}
//获取上传的文件名称
$this->fileInfo['name'] = $file['name'];
//如果不指定保存文件名,则由系统默认
if(empty($savePath))$savePath = $this->savePath;
// 检查上传目录
if(!is_dir($savePath)) {
// 检查目录是否编码后的
if(is_dir(base64_decode($savePath))) {
$savePath = base64_decode($savePath);
}else{
// 尝试创建目录
if(!mkdir($savePath)){
$this->error = '上传目录'.$savePath.'不存在';
return false;
}
}
}else {
if(!is_writeable($savePath)) {
$this->error = '上传目录'.$savePath.'不可写';
return false;
}
}
//上传的文件路径
$this->fileInfo['savepath'] = $savePath;
//获取文件后缀
$this->fileInfo['ext'] = $this->getExt($file["name"]);
//判断是否是允许上传的文件格式
if(!empty($this->allowExts)){
if(!in_array($this->fileInfo['ext'], $this->allowExts)){
$this->error = "上传文件格式错误";
return false;
}
}
//获取文件大小
$this->fileInfo['size'] = $file['size'];
//判断文件是否超过设置的文件大小
if($this->maxSize != "-1"){
if($this->maxSize<$this->fileInfo['size']){
$this->error = "上传的文件过大";
return false;
}
}
//上传后新文件的文件名
$this->fileInfo["savename"] = date("YmdHis").".".$this->fileInfo["ext"];
$this->fileInfo["path"] = $this->fileInfo['savepath'].$this->fileInfo['savename'];
//上传文件
$bol = move_uploaded_file($file['tmp_name'],$this->fileInfo['savepath'].$this->fileInfo['savename']);
if(!$bol){
$this->error = "上传文件失败";
return false;
}
$this->fileInfo["success"] = "Yes";
return true;
}
//获取文件后缀
private function getExt($filename) {
$pathinfo = pathinfo($filename);
return $pathinfo['extension'];
}
//上传的信息
public function getFileInfo(){
return $this->fileInfo;
}
//错误信息
public function getError(){
return $this->error;
}
}
❺ 怎样用php实现上传图片到数据库
php实现上传图片保存到数据库的方法。具体分析如下:
php 上传图片,一般都使用move_uploaded_file方法保存在服务器上。但如果一个网站有多台服务器,就需要把图片发布到所有的服务器上才能正常使用(使用图片服务器的除外)
如果把图片数据保存到数据库中,多台服务器间可以实现文件共享,节省空间。
首先图片文件是二进制数据,所以需要把二进制数据保存在mysql数据库。
mysql数据库提供了BLOB类型用于存储大量数据,BLOB是一个二进制对象,能容纳不同大小的数据。
BLOB类型有以下四种,除存储的最大信息量不同外,其他都是一样的。可根据需要使用不同的类型。
TinyBlob 最大 255B
Blob 最大 65K
MediumBlob 最大 16M
LongBlob 最大 4G
数据表photo,用于保存图片数据,结构如下:
CREATETABLE`photo`(
`id`int(10)unsignedNOTNULLauto_increment,
`type`varchar(100)NOTNULL,
`binarydata`mediumblobNOTNULL,
PRIMARYKEY(`id`)
)ENGINE=MyISAMDEFAULTCHARSET=latin1AUTO_INCREMENT=1;
upload_image_todb.php代码如下:
<?php
//连接数据库
$conn=@mysql_connect("localhost","root","")ordie(mysql_error());
@mysql_select_db('demo',$conn)ordie(mysql_error());//判断action
$action=isset($_REQUEST['action'])?$_REQUEST['action']:'';
//上传图片
if($action=='add'){
$image=mysql_escape_string(file_get_contents($_FILES['photo']['tmp_name']));
$type=$_FILES['photo']['type'];
$sqlstr="insertintophoto(type,binarydata)values('".$type."','".$image."')";
@mysql_query($sqlstr)ordie(mysql_error());
header('location:upload_image_todb.php');
exit();
//显示图片
}elseif($action=='show'){
$id=isset($_GET['id'])?intval($_GET['id']):0;
$sqlstr="select*fromphotowhereid=$id";
$query=mysql_query($sqlstr)ordie(mysql_error());
$thread=mysql_fetch_assoc($query);
if($thread){
header('content-type:'.$thread['type']);
echo$thread['binarydata'];
exit();
}
}else{
//显示图片列表及上传表单
?>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="content-type"content="text/html;charset=utf-8">
<title>uploadimagetodbdemo</title>
</head>
<body>
<formname="form1"method="post"action="upload_image_todb.php"enctype="multipart/form-data">
<p>图片:<inputtype="file"name="photo"></p>
<p><inputtype="hidden"name="action"value="add"><inputtype="submit"name="b1"value="提交"></p>
</form>
<?php
$sqlstr="select*fromphotoorderbyiddesc";
$query=mysql_query($sqlstr)ordie(mysql_error());
$result=array();
while($thread=mysql_fetch_assoc($query)){
$result[]=$thread;
}
foreach($resultas$val){
echo'<p><img
src="upload_image_todb.php?action=show&id='.$val['id'].'&t='.time().'"
width="150"></p>';
}
?>
</body>
</html>
<?php
}
?>
程序运行截图和数据库截图:
❻ win8.1下 使用php开发的系统中上传图片功能老是不行,图片不能正常上传,不知道是不是系统原因
上传图片的时候,你上传的图片会暂存到服务器的一个临时目录下, 你在上传的php中 输出一下 文件上传到的路径,看看这个路径下有这个文件没,是不是 这个放文件的文件夹没有写权限