PHP調用介面到阿里雲OSS同步上傳圖片____PHP

來源:互聯網
上載者:User

1、當然一些OSS的配製我就不再寫了,因為阿里雲上面有個Demo,裡面有好多種調用方法去上傳到OSS上,你自己去看一下就明白是怎麼做了呢,我這裡要寫的是比較簡單的PHP上傳圖片到阿里雲OSS滴,而是不需要一些複雜的代碼,僅僅適合輕量級的上傳圖片

這裡有最新Demo下載地址和阿里雲官方下載地址:

http://pan.baidu.com/s/1c0e1bOG

http://docs.aliyun.com/?spm=5176.383663.9.7.VguL7J#/pub/oss/sdk/sdk-download&php


2、代碼如下啦

 <form name='form1' class="personal_info_add_order_manually" ENCTYPE="multipart/form-data"  action="insert.php" method="post">

<input type='file' name='file' value='' />


</form>

<?php

/*引入阿里雲OSS同步上傳圖片*/
require('./aliyunoss/sdk.class.php');
$oss_sdk_service = new ALIOSS();
//設定是否開啟curl偵錯模式
$oss_sdk_service->set_debug_mode(FALSE);try{
 /*阿里開始以擷取內容的方式開始上傳到bucket Start*/
                    $content = '';
                    $length = 0;
                    $fp = fopen($_FILES["file"]["tmp_name"], 'r'); //這裡就是input中類型是file名字是file
                    if ($fp) {
                        $f = fstat($fp);
                        $length = $f['size'];
                        while (!feof($fp)) {
                            $content .= fgets($fp, 8888);
                        }
                    }
                    $bucket = 'test-image';
                    $pic_name = $user_id.'_'.time().$_FILES["file"]["name"];//拼接的參數
                    $upload_file_options = array('content' => $content, 'length' => $length);//上傳用到的參數
                    $upload_file_by_content = $oss_sdk_service->upload_file_by_content($bucket, $pic_name, $upload_file_options); //$_FILES["file"]["name"]這個就是檔案名稱,你可以自己定義的。
                    $pic_path = "http://oss.aliyuncs.com/" . $bucket . "/" .$pic_name;//最終擷取上傳圖片的路徑
                    /*阿里開始以擷取內容的方式開始上傳到bucket End*/
                        //upload_by_multi_part($oss_sdk_service);
            //move_uploaded_file($_FILES["file"]["tmp_name"],'d:\\clientweb\\htback'.$pic_path);
            $sql="insert into htback.tblordermanual(user_id,merchant_name,order_no,order_date,pic_path,create_date,status_id) values('$user_id','$merchant_name','$order_no','$order_date','$pic_path',now(),0)";
            //echo $sql;
            $wpdb->query($sql);    
            echo "<script language=\"javascript\">alert('".__("<!--:zh-->提交成功,請等待客服人員審核。<!--:--><!--:en-->Saved successfully.<!--:-->")."');parent.close_add();</script>";


?>

===============================================================================================================================

二當家的官網,請訪問 http://www.erdangjiade.com

更多商城企業源碼,盡在 http://www.erdangjiade.com/source

更多原創模板,盡在 http://www.erdangjiade.com/templates  

網頁特效下載:www.erdangjiade.com/js

PHP/Mysql:www.erdangjiade.com/php
     
PHP網站開發求職QQ群 368848856

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.