gknauf: curl-www/libcurl/php/examples ftpupload.php,1.2,1.3
[email protected] Thu, 03 Sep 2009 17:47:22 +0000
| Newsgroups | gmane.comp.web.curl.www.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/curl/curl-www/libcurl/php/examples
In directory labb:/tmp/cvs-serv25562
Modified Files:
ftpupload.php
Log Message:
fixed PHP ftp sample (missing semicolon, use binary mode);
modified a bit to show how the URL is build from the singe informations.
Index: ftpupload.php
===================================================================
RCS file: /cvsroot/curl/curl-www/libcurl/php/examples/ftpupload.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ftpupload.php 9 Jun 2006 07:44:05 -0000 1.2
+++ ftpupload.php 3 Sep 2009 17:47:20 -0000 1.3
@@ -3,14 +3,20 @@
// A simple PHP/CURL FTP upload to a remote site
//
+$localfile = "me-and-my-dog.jpg";
+$ftpserver = "ftp.mysite.com";
+$ftppath = "/path/to";
+$ftpuser = "myname";
+$ftppass = "mypass";
+
+$remoteurl = "ftp://${ftpuser}:${ftppasswd}@${ftpserver}${ftppath}/${localfile}";
+
$ch = curl_init();
-$localfile = "me-and-my-dog.jpg"
-$fp = fopen ($localfile, "r");
+$fp = fopen($localfile, "rb");
// we upload a JPEG image
-curl_setopt($ch, CURLOPT_URL,
- "ftp://mynamw:[email protected]/path/to/destination.jpg");
+curl_setopt($ch, CURLOPT_URL, $remoteurl);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
@@ -18,9 +24,9 @@
// extra error checking on the upload.
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
-$error = curl_exec ($ch);
+$error = curl_exec($ch);
// check $error here to see if it did fine or not!
-curl_close ($ch);
+curl_close($ch);
?>