導航:首頁 > 編程語言 > 微信上傳圖片php

微信上傳圖片php

發布時間:2022-05-19 04:28:32

1. php開發微信jssdk介面 iphone手機當一次多圖上傳時,只有一張上傳成功怎麼回事,安

微信上傳圖片,只能遞歸方法上傳多張,所以你可能是JS代碼里只上傳了一次

2. 如何在微信上上傳圖片

1
第一,打開你的微信。上傳照片的話你肯定要打開你的手機微信界面,不然你怎麼傳照片呢?
2
第二,進入「我的相冊」,可以看到一個相機的標志,你點那個標志就可以了。
3
第三,點擊微信裡面的「朋友圈」,到了「朋友圈」頁面再點右上角自己的頭像進入到「我的相冊」,點擊相機的標志,也同樣可以上傳的

3. 手機微信如何上傳圖片

方法/步驟

打開手機微信

在手機微信里點擊文件傳送助手,在點開+標志。

單機手機里的相冊。

在手機相冊里選擇圖片,點擊發送。

手機圖片傳到電腦上。

點擊圖片,將圖片保存到電腦上。

注意事項

手機電腦都要連接WIF

4. 各位大神,微信小程序用戶上傳的圖片怎麼用PHP存儲到資料庫

通常是將圖片的地址存儲到資料庫,上傳之後,應該能獲得圖片的保存地址,然後把這個圖片地址以字元串形式存儲到資料庫里。

5. 微信小程序如何使用PHP實現文件上傳

調用小程序文件上傳api
伺服器接收到微信post過來的文件之後,php處理代碼和傳統文件上傳代碼一樣

6. PHP 微信上傳永久素材

http請求方式: POST/FORM
http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
調用示例(使用curl命令,用FORM表單方式上傳一個多媒體文件):
curl -F [email protected] "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"

你這種情況屬於使用curl命令的方式傳值,幫助文檔:http://linux.51yip.com/search/curl

正確情況下的返回JSON數據包結果如下:{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789}
錯誤情況下的返回JSON數據包示例如下(示例為無效媒體類型錯誤):{"errcode":40004,"errmsg":"invalid media type"}
另外全局返回碼說明:https://mp.weixin.qq.com/wiki/17/.html

7. php開發手機網站上傳圖片問題!

讀取上傳的文件的流,然後用gd庫創建空白圖形,然後把流扔進去
$filename = $_FILE['tmp_name'];

$fd = fopen($filename, "r" );
$contents = fread($fd, filesize($filename));
fclose( $fd );
然後用gd庫函數,創建圖片資源,把上面得到的流寫進去

8. 微信上傳圖片報錯 {"errcode":41005,"errmsg":"media data missing"}

這個問題有可能和php版本有關系,可以試試php的其他版本,我也遇見過這個問題,當時用php的版本是5.6.3,結果執行就報這個錯誤,換了5.5.1或者5.4.3都可以順利執行,應該是curl_setopt函數在不同版本下執行有區別 吧

9. php微信上傳永久圖片素材求代碼

您好,這樣的:
//素材
const MEDIA_FOREVER_UPLOAD_URL = '/material/add_material?';
const MEDIA_FOREVER_NEWS_UPLOAD_URL = '/material/add_news?';
const MEDIA_FOREVER_NEWS_UPDATE_URL = '/material/update_news?';
const MEDIA_FOREVER_GET_URL = '/material/get_material?';
const MEDIA_FOREVER_DEL_URL = '/material/del_material?';
const MEDIA_FOREVER_COUNT_URL = '/material/get_materialcount?';
const MEDIA_FOREVER_BATCHGET_URL = '/material/batchget_material?';

/**
* 上傳臨時素材,有效期為3天(認證後的訂閱號可用)
* 注意:上傳大文件時可能需要先調用 set_time_limit(0) 避免超時
* 注意:數組的鍵值任意,但文件名前必須加@,使用單引號以避免本地路徑斜杠被轉義
* 注意:臨時素材的media_id是可復用的!
* @param array $data {"media":'@Path\filename.jpg'}
* @param type 類型:圖片:image 語音:voice 視頻:video 縮略圖:thumb
* @return boolean|array
*/
public function uploadMedia($data, $type){
if (!$this->access_token && !$this->checkAuth()) return false;
//原先的上傳多媒體文件介面使用 self::UPLOAD_MEDIA_URL 前綴
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_UPLOAD_URL.'access_token='.$this->access_token.'&type='.$type,$data,true);
if ($result)
{
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

/**
* 獲取臨時素材(認證後的訂閱號可用)
* @param string $media_id 媒體文件id
* @param boolean $is_video 是否為視頻文件,默認為否
* @return raw data
*/
public function getMedia($media_id,$is_video=false){
if (!$this->access_token && !$this->checkAuth()) return false;
//原先的上傳多媒體文件介面使用 self::UPLOAD_MEDIA_URL 前綴
//如果要獲取的素材是視頻文件時,不能使用https協議,必須更換成http協議
$url_prefix = $is_video?str_replace('https','http',self::API_URL_PREFIX):self::API_URL_PREFIX;
$result = $this->http_get($url_prefix.self::MEDIA_GET_URL.'access_token='.$this->access_token.'&media_id='.$media_id);
if ($result)
{
if (is_string($result)) {
$json = json_decode($result,true);
if (isset($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
}
return $result;
}
return false;
}

/**
* 上傳永久素材(認證後的訂閱號可用)
* 新增的永久素材也可以在公眾平台官網素材管理模塊中看到
* 注意:上傳大文件時可能需要先調用 set_time_limit(0) 避免超時
* 注意:數組的鍵值任意,但文件名前必須加@,使用單引號以避免本地路徑斜杠被轉義
* @param array $data {"media":'@Path\filename.jpg'}
* @param type 類型:圖片:image 語音:voice 視頻:video 縮略圖:thumb
* @param boolean $is_video 是否為視頻文件,默認為否
* @param array $video_info 視頻信息數組,非視頻素材不需要提供 array('title'=>'視頻標題','introction'=>'描述')
* @return boolean|array
*/
public function uploadForeverMedia($data, $type,$is_video=false,$video_info=array()){
if (!$this->access_token && !$this->checkAuth()) return false;
//#TODO 暫不確定此介面是否需要讓視頻文件走http協議
//如果要獲取的素材是視頻文件時,不能使用https協議,必須更換成http協議
//$url_prefix = $is_video?str_replace('https','http',self::API_URL_PREFIX):self::API_URL_PREFIX;
//當上傳視頻文件時,附加視頻文件信息
if ($is_video) $data['description'] = self::json_encode($video_info);
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_UPLOAD_URL.'access_token='.$this->access_token.'&type='.$type,$data,true);
if ($result)
{
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

/**
* 上傳永久圖文素材(認證後的訂閱號可用)
* 新增的永久素材也可以在公眾平台官網素材管理模塊中看到
* @param array $data 消息結構{"articles":[{...}]}
* @return boolean|array
*/
public function uploadForeverArticles($data){
if (!$this->access_token && !$this->checkAuth()) return false;
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_NEWS_UPLOAD_URL.'access_token='.$this->access_token,self::json_encode($data));
if ($result)
{
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

/**
* 修改永久圖文素材(認證後的訂閱號可用)
* 永久素材也可以在公眾平台官網素材管理模塊中看到
* @param string $media_id 圖文素材id
* @param array $data 消息結構{"articles":[{...}]}
* @param int $index 更新的文章在圖文素材的位置,第一篇為0,僅多圖文使用
* @return boolean|array
*/
public function updateForeverArticles($media_id,$data,$index=0){
if (!$this->access_token && !$this->checkAuth()) return false;
if (!isset($data['media_id'])) $data['media_id'] = $media_id;
if (!isset($data['index'])) $data['index'] = $index;
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_NEWS_UPDATE_URL.'access_token='.$this->access_token,self::json_encode($data));
if ($result)
{
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

/**
* 獲取永久素材(認證後的訂閱號可用)
* 返回圖文消息數組或二進制數據,失敗返回false
* @param string $media_id 媒體文件id
* @param boolean $is_video 是否為視頻文件,默認為否
* @return boolean|array|raw data
*/
public function getForeverMedia($media_id,$is_video=false){
if (!$this->access_token && !$this->checkAuth()) return false;
$data = array('media_id' => $media_id);
//#TODO 暫不確定此介面是否需要讓視頻文件走http協議
//如果要獲取的素材是視頻文件時,不能使用https協議,必須更換成http協議
//$url_prefix = $is_video?str_replace('https','http',self::API_URL_PREFIX):self::API_URL_PREFIX;
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_GET_URL.'access_token='.$this->access_token,self::json_encode($data));
if ($result)
{
if (is_string($result)) {
$json = json_decode($result,true);
if (isset($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return $result;
}
return false;
}

/**
* 刪除永久素材(認證後的訂閱號可用)
* @param string $media_id 媒體文件id
* @return boolean
*/
public function delForeverMedia($media_id){
if (!$this->access_token && !$this->checkAuth()) return false;
$data = array('media_id' => $media_id);
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_DEL_URL.'access_token='.$this->access_token,self::json_encode($data));
if ($result)
{
$json = json_decode($result,true);
if (!$json || !empty($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return true;
}
return false;
}

/**
* 獲取永久素材列表(認證後的訂閱號可用)
* @param string $type 素材的類型,圖片(image)、視頻(video)、語音 (voice)、圖文(news)
* @param int $offset 全部素材的偏移位置,0表示從第一個素材
* @param int $count 返回素材的數量,取值在1到20之間
* @return boolean|array
* 返回數組格式:
* array(
* 'total_count'=>0, //該類型的素材的總數
* 'item_count'=>0, //本次調用獲取的素材的數量
* 'item'=>array() //素材列表數組,內容定義請參考官方文檔
* )
*/
public function getForeverList($type,$offset,$count){
if (!$this->access_token && !$this->checkAuth()) return false;
$data = array(
'type' => $type,
'offset' => $offset,
'count' => $count,
);
$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_BATCHGET_URL.'access_token='.$this->access_token,self::json_encode($data));
if ($result)
{
$json = json_decode($result,true);
if (isset($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

/**
* 獲取永久素材總數(認證後的訂閱號可用)
* @return boolean|array
* 返回數組格式:
* array(
* 'voice_count'=>0, //語音總數量
* 'video_count'=>0, //視頻總數量
* 'image_count'=>0, //圖片總數量
* 'news_count'=>0 //圖文總數量
* )
*/
public function getForeverCount(){
if (!$this->access_token && !$this->checkAuth()) return false;
$result = $this->http_get(self::API_URL_PREFIX.self::MEDIA_FOREVER_COUNT_URL.'access_token='.$this->access_token);
if ($result)
{
$json = json_decode($result,true);
if (isset($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
return $json;
}
return false;
}

10. PHP 微信端上傳圖片,上傳logo和banner圖,哪位大神傳授一下經驗啊,有demo更好,可以加分

<divclass="header">
<span>頭像</span>
<divclass="head_r"style="position:relative">
<imgclass="portrait_line"id="show_portrait"src="{$agent['portrait']}">
<imgsrc="__IMAGES__/more.png">
<inputtype="file"name="portrait"id="portrait"data-server="{:U('Home/Upload/mobile_upload_portrait')}"style="width:100%;height:100%;position:absolute;left:0px;top:0px;opacity:0;">
</div>
</div>

最後一個input file弄成透明的,占據整個你要觸發上傳的位置。

重點在下面,用原生ajax上傳提交圖片,並把上傳後伺服器本地的地址傳回來,通過js付到表單里,並把圖片縮小預覽貼出來。

<script>
$(function(){
$("input#portrait").on("change",function(){
changepic('portrait','show_portrait');
});
});

varxhr;
varreturnimg="";
varreturninput="";

functionchangepic(id,img,input){
returnimg=img;
returninput=input;
varfileObj=document.getElementById(id).files[0];
varuploadServer=$("#"+id).attr("data-server");
varform=newFormData();
form.append("portrait",fileObj);
createXMLHttpRequest();
xhr.onreadystatechange=handleStateChange;
xhr.open("post",uploadServer,true);
xhr.send(form);
}

functioncreateXMLHttpRequest()
{
if(window.ActiveXObject)
{
xhr=newActiveXObject("Microsoft.XMLHTTP");
}
elseif(window.XMLHttpRequest)
{
xhr=newXMLHttpRequest();
}
}
functionhandleStateChange()
{
var$loading=layer.open({type:2,})
if(xhr.readyState==4)
{
if(xhr.status==200||xhr.status==0)
{
varresult=xhr.responseText;
varjson=eval("("+result+")");
if(json.result=='success'){
$.ajax({
type:'post',
url:'/index.php/Wap/Self/updatePortrait',
data:{
portrait:json.url,
},
success:function(){

},
error:function(){
alert('伺服器錯誤');
},
});
$("#"+returnimg).attr("src",json.url);
layer.close($loading);
}
else{
alert('上傳頭像失敗'+json.msg);
layer.close($loading);
}

}
}
}
</script>

然後是ajax上傳的介面

publicfunctionmobile_upload_portrait(){//手機端上傳頭像
if(IS_POST){
$upload=newUpload();
$upload->maxSize=3*1024*1024;//3M
$upload->exts=array('jpg','gif','png','jpeg');
$upload->rootPath='./';
$upload->savePath='/Uploads/';
$upload->autoSub=true;
$upload->subName=array('date','Ymd');
$upload->saveName='uniqid';
if(!is_dir($upload->savePath)){
mkdir($upload->savePath);
}
$info=$upload->uploadOne($_FILES['portrait']);
if(!$info){
$result=array('result'=>'fail','msg'=>'請上傳3M以下的圖片');
}else{
$result=array('result'=>'success','url'=>$info['savepath'].$info['savename']);
}
$this->ajaxReturn($result);
}
}

代碼是Thinkphp的項目截出來的,頁面上有模板的痕跡,最後一段php的介面,也用了tp自帶的文件上傳類。不過看得懂的話,這些都不影響理解。

閱讀全文

與微信上傳圖片php相關的資料

熱點內容
二次元表格編程 瀏覽:20
plc編程器保停 瀏覽:963
如何降低伺服器的內存佔用率 瀏覽:868
阿里雲伺服器是個什麼意思 瀏覽:817
國內最好的數控編程培訓學校 瀏覽:13
222乘104列是演算法 瀏覽:159
程序員溝通正確姿勢 瀏覽:969
魔玩app怎麼視頻推廣 瀏覽:960
程序員抽獎送禮 瀏覽:458
北京java程序員薪資 瀏覽:658
如何創建網路平台或者app 瀏覽:355
python隨機數生成控制概率 瀏覽:235
壓縮機並聯運行 瀏覽:899
兩位單片機 瀏覽:63
四川音樂類投檔線的演算法 瀏覽:650
建行app如何改轉賬卡 瀏覽:26
android開發升級 瀏覽:299
要火社區app進不去怎麼辦 瀏覽:826
安卓手機上的自定義功能怎麼用 瀏覽:230
方舟伺服器怎麼購買進去資格 瀏覽:44