PHP call interface to Aliyun oss sync upload picture ____php

Source: Internet
Author: User
Tags php website aliyun

1, of course, some of the preparation of OSS I will not write, because Aliyun has a demo, there are many ways to upload to the OSS, you go to see how you do it, I want to write here is relatively simple PHP upload pictures to Aliyun oss drip, but do not need some complex code, Just for lightweight upload pictures

Here are the latest demo download address and Aliyun official download address:

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

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


2, the code is as follows

<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

* * Introduction of Aliyun OSS Synchronous upload images * *
Require ('./aliyunoss/sdk.class.php ');
$oss _sdk_service = new Alioss ();
Set whether to turn on Curl Debug mode
$oss _sdk_service->set_debug_mode (FALSE); try{
/* Ali started uploading to bucket start*/in the form of fetching content
$content = ';
$length = 0;
$fp = fopen ($_files["file"] ["Tmp_name"], ' r '); This is the input type, the file name is 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"];//splicing parameters
$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"] This is the filename, you can define it yourself.
$pic _path = "http://oss.aliyuncs.com/". $bucket. "/". $pic _name;//finally get the path to the uploaded image
/* Ali started uploading to bucket end*/in the form of fetching content
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--> submitted successfully, please wait for the hospitality staff to review." <!--:--><!--: en-->saved successfully.<!--:--> "); Parent.close_add ();</script> ";


?>

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

Two-headed official website, please visit http://www.erdangjiade.com

More Mall Enterprise source code, do in Http://www.erdangjiade.com/source

More original template, do in http://www.erdangjiade.com/templates

Web effects Download: Www.erdangjiade.com/js

php/mysql:www.erdangjiade.com/php

PHP website Development Job QQ Group 368848856

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.