note 121973 added to function.curl-setopt

From: Date: Mon, 04 Dec 2017 14:59:35 +0000
Subject: note 121973 added to function.curl-setopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-209308@lists.php.net to get a copy of this message
This is howto upload an existing file to an FTP server with cURL in PHP. You should remember that CURLOPT_URL should contain the file's basename to save on the FTP server. For example, if you upload hello.txt to ftp://www.wuxiancheng.cn/text/, CURLOPT_URL should be ftp://www.wuxiancheng.cn/text/hello.txt rather than ftp://www.wuxiancheng.cn/text/, otherwise you will get an error message like "Uploading to a URL without a file name! " when you call curl_error(); <?php $ch = curl_init(); $filepath = 'D:\Web\www\wuxiancheng.cn\hello.txt'; $basename = pathInfo($filepath, PATHINFO_BASENAME); $filesize = fileSize($filepath); curl_setopt_array( $ch, array( CURLOPT_URL => 'ftp://www.wuxiancheng.cn/text/' . $basename, CURLOPT_USERPWD => 'USERNAME:PASSWORD', CURLOPT_PROTOCOLS => CURLPROTO_FTP, CURLOPT_UPLOAD => true, CURLOPT_INFILE => $filepath, CURLOPT_INFILESIZE => $filesize, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, ) ); curl_exec($ch); $message = curl_errno($ch) === CURLE_OK ? 'success' : 'failure'; echo $message; ?> ---- Server IP: 208.43.231.9 Probable Submitter: 118.117.77.148 ---- Manual Page -- http://php.net/manual/en/function.curl-setopt.php Edit -- https://master.php.net/note/edit/121973 Del: integrated -- https://master.php.net/note/delete/121973/integrated Del: useless -- https://master.php.net/note/delete/121973/useless Del: bad code -- https://master.php.net/note/delete/121973/bad+code Del: spam -- https://master.php.net/note/delete/121973/spam Del: non-english -- https://master.php.net/note/delete/121973/non-english Del: in docs -- https://master.php.net/note/delete/121973/in+docs Del: other reasons-- https://master.php.net/note/delete/121973 Reject -- https://master.php.net/note/reject/121973 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#209308) next »