php多圖片上傳dome,php上傳多張圖片

本文目錄一覽:

ThinkPHP中圖片最多一次上傳20張,怎麼上傳更多圖片?

$User-fenxiang_fm = ‘Uploads/’.$info[0][“savename”]; // 這裡的$info[0][“savename”]的下標[0]表示上傳的第1個圖片按順序,記住是下標

$User-fenxiang_sc = ‘Uploads/’.$info[1][“savename”]; // 這裡的$info[1][“savename”]的下標[1]表示上傳的第2個圖片按順序,記住是下標

function upload(){

import(“ORG.Net.UploadFile”);

$upload = new UploadFile();// 實例化上傳類

$upload-maxSize = 3145728 ;// 設置附件上傳大小

$upload-allowExts = array(‘jpg’, ‘gif’, ‘png’, ‘jpeg’);// 設置附件上傳類型

$upload-saveRule = time;//這裡的時間是根據上傳的圖片的多少來自動改變圖片的名稱的(並且時間都不同,所以上傳的圖片的名稱就不會相同)

php怎麼一個file上傳多張圖片?????????

?php /** *類說明: * 使用new關鍵字實像化類,類中有兩個公用方法, * 方法create_input創建表單按鍵,請在相應的表單處引用該方法就可創建上傳表單的input按鍵 * 方法get_upfile()用於處理上傳文件 * 該類由 游天小蝦 製作,網頁製作交流群:69574955 * **/ class upfile { private $name = ‘filename’;//input表單名 private $namecount = 2;//設置上傳文件的個數 private $type = array(‘jpg’,’jpeg’,’gif’,’png’);//文件格式 private $size = ‘1024’;//文件大小單位kb private $upname = ”;//上傳文件信息 private $updir = ‘upfile/’; private $movename = ”;//移動後的文件名 private $uparrs = array();//多文件上傳數組 private $error_type =0;//文件上傳產生的錯誤 /** * 創建文件上傳的表單控制項 * */ public function create_input(){ if(floor($this-namecount) == 1){ $input = “pinput type=’file’ id=”.$this-name.” name=”.$this-name.”/p”; }else{ for($i=0;$i($this-namecount);$i++){ $input .= “pinput type=’file’ id='”.$this-name.”[]’ name='”.$this-name.”[]’/p”; } } echo “$input”; } /** * 初始文件信息$file = $_FILES[‘file’][‘tem_name’] * **/ private function get_part(){ if($this-namecount == 1){ //判斷是否是多文件上傳 if($_FILES[$this-name][‘tmp_name’]){ $this-upname = $_FILES[$this-name]; }else{ $this-error_type += 100; //文件信息錯誤觀點 100; } }else{ if($_FILES[$this-name]){ $this-uparrs = $this-more_updata($_FILES[$this-name],$this-namecount);//對$_FILES取得的文件上信息重寫 }else{ $this-error_type += 100; //文件信息錯誤觀點 100; } } } /** * 多文件上傳時,數組重寫 * **/ private function more_updata($arrs,$num){ for($i=0;$i$num;$i++){ $data[] =array(‘name’=$arrs[name][$i],’type’=$arrs[type][$i],’tmp_name’=$arrs[tmp_name][$i],’error’=$arrs[‘error’][$i],’size’=$arrs[‘size’][$i]); } return $data; } /** * 判斷上傳文件大小 * **/ private function chck_size(){ if($this-upname[‘size’]*1000 $this-size){ $this-error_type += 300; //文件信息錯誤觀點 300; } } /** * 判斷上傳文件的類型 * **/ private function chck_type(){ if(!in_array($this-get_suffix($this-upname[‘name’]),$this-type)){ $this-error_type += 500; //文件信息錯誤觀點 500; } } /** * 格式化上傳後的文件名 * **/ private function chck_name(){ $this-movename = date(Ymd).substr(md5(rand(0,date(Hms))),0,6).”.”; $this-movename .= $this-get_suffix($this-upname[‘name’]); } /** * 移動文件 * **/ private function move_file(){ if($this-updir){ if(!move_uploaded_file($this-upname[‘tmp_name’],$this-updir.$this-movename)){ $this-error_type += 700; //文件信息錯誤觀點 700; } }else{ mkdir($this-updir,”w”); chmod($this-updir,777); if(!move_uploaded_file($this-upname[‘tmp_name’],$this-updir.$this-movename)){ $this-error_type += 700; //文件信息錯誤觀點 700; } } } /** * 取得文件的後綴名 * **/ private function get_suffix($filename){//取得文件後綴名 $part = pathinfo($filename); $suffix = $part[‘extension’]; return $suffix; } /** * 文件上傳處理 * **/ public function get_upfile() {//主上傳方法 if(floor($this-namecount) == 1){ $this-get_part(); $this-chck_name(); $this-chck_type(); $this-chck_size(); if($this-error_type ==0){$this-move_file();} if($this-error_type ==0){ echo “$this-movename 上傳成功 br”; }else{ echo “$this-movename 上傳失敗,錯誤: $this-error_type br”; $this-error_type=0; }; }else{ $this-get_part(); for($i=0;$ifloor($this-namecount);$i++){ $this-upname = ($this-uparrs[$i]); $this-chck_name(); $this-chck_type(); $this-chck_size(); if($this-error_type ==0){$this-move_file();} if($this-error_type ==0){ echo “$this-movename 上傳成功 br”; }else{ echo “$this-movename 上傳失敗,錯誤: $this-error_type br”; $this-error_type=0; }; } } } } $up = new upfile(); if($_POST[‘t1′]){ $up-get_upfile(); } ? form name=’f1′ enctype = multipart/form-data action=”” method=”post” input type=’text’ name=’t1’br ?php $up-create_input(); ? input type=’submit’ value=’上傳’ /from 剛不久寫的一個文件上傳的類!上面已經有說明了,你參考一下,不明白的話,可以問我,或者加入我們的QQ群討論!

php 怎樣實現同時上傳多張圖片

有詳細的注釋,不清楚直接CALL我

主要是利用了JS來控制文件域,增加或者刪除來實現的。

!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”

html xmlns=””

head

meta http-equiv=”Content-Type” content=”text/html; charset=gbk” /

meta name=”Keywords” content=””/

meta name=”Description” content=””/

title動態添加圖片/title

script type=”text/javascript”

function addimg(){

//包含所有文件域的DIV

var div = document.getElementById(‘imgs’);

//文件域

var input = document.createElement(“input”);

input.name = “img[]”;

input.type = ‘file’;

//添加

div.appendChild(input);

//刪除按鈕

var button = document.createElement(“a”);

button.href = “javascript:;”;

button.innerHTML = ‘刪除’;

div.appendChild(button);

//換行

var br = document.createElement(“br”);

div.appendChild(br);

//在按鈕上增加刪除的事件

button.onclick = function(){

input.parentNode.removeChild(input);

this.parentNode.removeChild(this);

br.parentNode.removeChild(br);

}

}

/script

/head

body

form method=”POST” enctype=”multipart/form-data” action=”upload.php”

請選擇圖片:

div id=”imgs”

input type=”file” name=”img[]”/br/

/div

input type=”button” onclick=”addimg()” value=”增加”/

/form

/body

/html

多張圖片上傳 刪除 修改 PHP

方法一:

你這樣以json

的形式保持多條記錄

不好修改數據記錄的,程序些下來也比較糾結

改一下數據表裡面的結構吧,,,一張圖片一個欄位(pic1,pic2,pic3,pic4)

方法二:

在修改頁面的時候

json

數據

格式化為

數組

用foreach

把這些圖片路徑

循環到

隱藏域裡面

點擊刪除

一個

時候

就用js

刪除圖片對應的隱藏域

(至於圖片的刪除

可以用ajax

來實現)

最後表單提交的時候

就值接收到了

沒有刪除的圖片的隱藏域

保存更改入庫就

行了!

希望對你有用

php 非同步上傳圖片幾種方法總結

代碼如下

form action=”upload.php” id=”form1″ name=”form1″ enctype=”multipart/form-data” method=”post” target=”uploadIframe” !–上傳圖片頁面 — /form iframe name=”uploadIframe” id=”uploadIframe” style=”display:none”/iframe

然後後台處理完上傳圖片邏輯後返回給前台,利用ajax修改當前頁面DOM對象實現無刷新上傳圖片的友好功能。

實例

代碼如下

a.html form enctype=”multipart/form-data” action=”a.php” target=”ifram_sign” method=”POST” input name=”submit” id=”submit” value=”” type=”hidden” label上傳文件: input name=”test_file” type=”file” id=”test_file” size=”48″/label input type=”image” value=”立即上傳” id=”submit_btn” /formiframe name=”ifram_sign” src=”” frameborder=”0″ height=”0″ width=”0″ marginheight=”0″ marginwidth=”0″/iframe

php代碼:

代碼如下

?php

if ($_files[“test_file”][“error”] 0)

{

echo “Error: ” . $_files[“test_file”][“error”] . “br /”;

}

else

{

//這裡的判斷圖片屬性的方法就不寫了。自己擴展一下。

$filetype=strrchr($_files[“test_file”][“name”],”.”);

$filetype=substr($filetype,1,strlen($filetype));

$filename=”img/”.time(“YmdHis”).”.”.$filetype;

move_uploaded_file($_files[“test_file”][“tmp_name”],$filename);

echo ‘script alert(1)/script’;

$return=”parent.document.getElementByIdx_x(‘mpic”.$pageset_id.”‘).innerhtml='”.$dataimgpath.”‘”;

echo “script alert(‘上傳成功’)/script”;

echo “script{$return}/script”;

}

?

其實jquery ajax圖片非同步上傳

html:

!DOCTYPE html PUBLIC “-//W3C//dtd Xhtml 1.0 transitional//EN”

“”

html xmlns=”” lang=”en_US” xml:lang=”en_US”

head

title圖片非同步上傳/title

/head

script type=”text/javascript” src=”js/jquery.js”/script

script type=”text/javascript” src=”js/index.js”/script

link type=”text/css” rel=”stylesheet” href=”css/index.css”

body

div class=”frm”

form name=”uploadFrom” id=”uploadFrom” action=”upload.php” method=”post” target=”tarframe” enctype=”multipart/form-data”

input type=”file” id=”upload_file” name=”upfile”

/form

iframe src=”” width=”0″ height=”0″ style=”display:none;” name=”tarframe”/iframe

/div

div id=”msg”

/div

/body

/html

index.js

$(function(){

$(“#upload_file”).change(function(){

$(“#uploadFrom”).submit();

});

});

function stopSend(str){

var im=”img src=’upload/images/”+str+”‘”;

$(“#msg”).append(im);

}

upload.php

?php

$file=$_files[‘upfile’];

$name=rand(0,500000).dechex(rand(0,10000)).”.jpg”;

move_uploaded_file($file[‘tmp_name’],”upload/images/”.$name);

//調用iframe父窗口的js 函數

echo “scriptparent.stopSend(‘$name’)/script”;

?

非同步上傳圖片幾種方法

php怎麼實現批量上傳圖片?不是一張一張選擇之後一起上傳 就是打開文件夾全選直接全部上傳。

獲取路徑下的所有圖片文件名,寫入資料庫或是某個變數,在別的頁面調用程序上傳,再從別的頁面讀出來就行了。

以下是示例代碼:

?php

function upload($fileName,$filePath)

{

//判斷該文件是否是用戶根據POST方式提交到伺服器的上傳文件

foreach($_FILES[$fileName][‘tmp_name’] as $k=$v)

{

if($_FILES[$fileName][‘name’][$k]!=””)

{

$result=check($_FILES[$fileName][‘size’][$k],$_FILES[$fileName][‘type’][$k],$_FILES[$fileName][‘name’][$k]);

if($result[‘error’]==1)

{

echo $result[‘msg’].”br”;

echo “出錯文件:”.$result[‘name’].”br”;

}

else

{

$arrTT=explode(“.”,$_FILES[$fileName][‘name’][$k]);

$extName=$arrTT[count($arrTT)-1];

$NewName=sha1(microtime()).”.”.$extName;

if(move_uploaded_file($v,$filePath.$NewName));

$arrWW[]=$NewName;

}

}

}

return $arrWW;

}

function check($size,$types,$name)

{

if($size=5242880)

{

$result[‘msg’]=’文件過大!’;

$result[‘error’]=1;

$result[‘name’]=$name;

}

$arrType=array(‘image/pjpeg’,’image/gif’,’image/x-png’,’audio/mp3′,’application/msword’,’application/vnd.ms_excel’,’application/octet-stream’,’application/vnd.ms-powerpoint’);

if(!in_array($types,$arrType))

{

$result[‘msg’]=’文件類型不匹配!’;

$result[‘error’]=1;

$result[‘name’]=$name;

}

return $result;

}

?

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/193347.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-01 15:00
下一篇 2024-12-01 15:01

相關推薦

  • 用Python繪製酷炫圖片

    在本篇文章中,我們將展示如何使用Python繪製酷炫的圖片。 一、安裝Python繪圖庫 在使用Python繪製圖片之前,我們需要先安裝Python繪圖庫。Python有很多繪圖庫…

    編程 2025-04-29
  • 使用axios獲取返回圖片

    使用axios獲取返回圖片是Web開發中很常見的需求。本文將介紹如何使用axios獲取返回圖片,並從多個方面進行詳細闡述。 一、安裝axios 使用axios獲取返回圖片前,首先需…

    編程 2025-04-29
  • Python 圖片轉表格

    本文將詳細介紹如何使用Python將圖片轉為表格。大家平時在處理一些資料的時候難免會遇到圖片轉表格的需求。比如從PDF文檔中提取表格等場景。當然,這個功能也可以通過手動複製、粘貼,…

    編程 2025-04-29
  • Python緩存圖片的處理方式

    本文將從多個方面詳細闡述Python緩存圖片的處理方式,包括緩存原理、緩存框架、緩存策略、緩存更新和緩存清除等方面。 一、緩存原理 緩存是一種提高應用程序性能的技術,在網路應用中流…

    編程 2025-04-29
  • Python如何抓取圖片數據

    Python是一門強大的編程語言,能夠輕鬆地進行各種數據抓取與處理。抓取圖片數據是一個非常常見的需求。在這篇文章中,我們將從多個方面介紹Python如何抓取圖片數據。 一、使用ur…

    編程 2025-04-29
  • Python利用Image加圖片的方法

    在Python中,利用Image庫可以快速處理圖片,並加入需要的圖片,本文將從多個方面詳細闡述這個操作。 一、Image庫的安裝和基礎操作 首先,我們需要在Python中安裝Ima…

    編程 2025-04-28
  • 百度網盤Python上傳

    百度網盤是一個常用的雲存儲平台,提供了多種上傳文件的方式,其中包括使用Python進行上傳。本文將從安裝Python、安裝依賴庫、上傳文件三個方面進行詳細闡述。 一、安裝Pytho…

    編程 2025-04-28
  • Avue中如何按照後端返回的鏈接顯示圖片

    Avue是一款基於Vue.js、Element-ui等技術棧的可視化開發框架,能夠輕鬆搭建前端頁面。在開發中,我們使用到的圖片通常都是存儲在後端伺服器上的,那麼如何使用Avue來展…

    編程 2025-04-28
  • 使用CKSlide實現圖片輪播

    CKSlide是一個基於jQuery的插件,可以方便地為網頁添加幻燈片和圖片輪播效果。使用CKSlide可以讓網站更加生動、活潑,給用戶帶來更好的體驗。 一、CKSlide基本用法…

    編程 2025-04-28
  • Python中使用socket傳輸圖片

    本文將從多個方面介紹如何使用Python中的socket模塊傳輸圖片,涉及到準備工作、發送方部分和接收方部分的詳細代碼實現。 一、準備工作 在使用Python中的socket模塊進…

    編程 2025-04-28

發表回復

登錄後才能評論