通过cURL从PHP中的POST表单发送文件

通过cURL从PHP中的POST表单发送文件,第1张

通过cURL从PHP中的POST表单发送文件

这是一些将文件发送到ftp的生产代码(对于您来说可能是一个很好的解决方案):

// This is the entire file that was uploaded to a temp location.$localFile = $_FILES[$fileKey]['tmp_name'];$fp = fopen($localFile, 'r');// Connecting to website.$ch = curl_init();curl_setopt($ch, CURLOPT_USERPWD, "email@email.org:password");curl_setopt($ch, CURLOPT_URL, 'ftp://@ftp.website.net/audio/' . $strFileName);curl_setopt($ch, CURLOPT_UPLOAD, 1);curl_setopt($ch, CURLOPT_TIMEOUT, 86400); // 1 Day Timeoutcurl_setopt($ch, CURLOPT_INFILE, $fp);curl_setopt($ch, CURLOPT_NOPROGRESS, false);curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'CURL_callback');curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localFile));curl_exec ($ch);if (curl_errno($ch)) {    $msg = curl_error($ch);}else {    $msg = 'File uploaded successfully.';}curl_close ($ch);$return = array('msg' => $msg);echo json_enpre($return);


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5588252.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存