How does php implement an api to upload files?

Source: Internet
Author: User
How does php implement an api to upload files? Now, if you want to upload wav, jpg, and other files through the upload api, please refer to the code provided by experts.


Reply to discussion (solution)

Http://wiki.open.t.qq.com/index.php? Oldid = 4665 & title = API % E9 % 8F % 82% E5 % 9B % A8 % E3 % 80% 82/% E5 % AF % B0 % EE % 86% BC % E5 % B4 % a5 % E9 % 8E % BA % E3 % 83% A5 % E5 % BD % 9B/% E9 % 8D % 99% E6 % 88% A3 % E3 % 80% E7 % 83% AF % EF % B9 % 80% EE % 98% BF % E5 % AF % AE % E7 % 8A % B2 % E6 % B5 % 98% E9 % 90% E5 % 9B % A9 % E6 % AE % 91% E5 % AF % B0 % EE % 86% BC % E5 % B4 % A5 There is a column.

If you have php code, how do you view the api source code?

How can this problem be solved? no one has replied. you only need the api server to save the binary stream file, or the image will work.

Apart from preparation, isn't move_uploaded_file a word?

How can I upload data through an api?

Please give me some code

Whose API?

Experts can write a simple api to upload images.

Upload an image or file. let's take a look at the code. thank you ..................!

I do not know how to upload files on the api server.

Write the same as form Upload

Http://www.w3school.com.cn/php/php_file_upload.asp

Require_once ".. /common_mysql.php "; require_once MESSAGE_PATH. 'zh/zh_calendar_message.php '; require_once "function_common/user_function.php"; require_once "function_common/public_function.php"; global $ DB; $ SQL _time = microtime (true); // $ uid = $ self_userid; // save the image $ json_result ['status'] = 0; $ path = 'upfile'; $ json_result ['status'] = 0; $ json_result ['successmsg '] = 'upload failed'; if (isset ($ _ FILES ['imagezi P ']) {$ upfile = 'upfile/'. $ _ FILES ['imagezip'] ['name']; if (! @ File_exists ($ path) {@ mkdir ($ path) ;}$ result = @ move_uploaded_file ($ _ FILES ['imagezip '] ['tmp _ name'], $ upfile); if (! $ Result) {$ json_result ['status'] = 0; $ json_result ['successmsg '] = 'upload failed '; $ json_result ['datas'] = array ('savepath' => $ upfile); exit (json_encode ($ json_result); }}$ json_result ['status'] = 1; $ json_result ['datas'] = array ('savepath' => $ upfile );


My server code, but how can someone POST data?

Now the question is how other people pass $ _ FILES through curl?


Can this be the only way? Can it be passed through curl?

$ File = realpath ('gif/1.gif '); // the file to be uploaded $ fields ['F'] = '@'. $ file; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, "Your api"); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ fields); curl_exec ($ ch); curl_close ($ ch );

OK. thank you. let me try it. thank you very much.

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.