❶ 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中 輸出一下 文件上傳到的路徑,看看這個路徑下有這個文件沒,是不是 這個放文件的文件夾沒有寫許可權