Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

php - Curl and post to upload a file to a server using an API

Im trying to upload a file using an API from a server. i'm using php 7.2 and all documentation from the api is for old php versions. Problem is I don't know how to send this file using curl. My code right know is something like this:

 CURLOPT_URL => “http://mySite/MyFolder/api/library?envelope=1”,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => “”,
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => “POST”,
    CURLOPT_POSTFIELDS => array(‘files’ => $_FILES[“UploadedMedia”], ‘expires’ => $fechaExpiracion),

I've never used curl before and the posts i've seen before use ftp or some other ways to upload files with curl but i have to do it using curl postfields and to the api url as far as i know. Any advice is welcome. Thanks in advance, Marco.

question from:https://stackoverflow.com/questions/65660289/curl-and-post-to-upload-a-file-to-a-server-using-an-api

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...