-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b356aa0
commit 0d0e191
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* 慕课网视频教学 | ||
* 代码实例-PHP-cURL实战 | ||
* 实例描述:把本地文件上传到FTP服务器上 | ||
*/ | ||
$curlobj = curl_init(); | ||
$localfile = 'ftp01.php'; | ||
$fp = fopen($localfile, 'r'); | ||
|
||
curl_setopt($curlobj, CURLOPT_URL, "ftp://192.168.1.100/ftp01_uploaded.php"); | ||
curl_setopt($curlobj, CURLOPT_HEADER, 0); | ||
curl_setopt($curlobj, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($curlobj, CURLOPT_TIMEOUT, 300); // times out after 300s | ||
curl_setopt($curlobj, CURLOPT_USERPWD, "peter.zhou:123456");//FTP用户名:密码 | ||
|
||
curl_setopt($curlobj, CURLOPT_UPLOAD, 1); | ||
curl_setopt($curlobj, CURLOPT_INFILE, $fp); | ||
curl_setopt($curlobj, CURLOPT_INFILESIZE, filesize($localfile)); | ||
$rtn = curl_exec($curlobj); | ||
fclose($fp); | ||
if(!curl_errno($curlobj)){ | ||
echo "Uploaded successfully."; | ||
} else { | ||
echo 'Curl error: ' . curl_error($curlobj); | ||
} | ||
curl_close($curlobj); | ||
?> |