Re: curl http file upload post
| From: | Chris | Date: | Tue, 04 Apr 2006 00:38:19 +0000 |
| Subject: | Re: curl http file upload post | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-233170@lists.php.net to get a copy of this message | ||
webmaster wrote:
I am trying to upload a file to a remote server using curl and post method here is what I have:You need the full filepath on the server - /path/to/test.txt. from this page: http://www.php.net/manual/en/function.curl-setopt.php looks like you need to add a curl_setopt call: CURLOPT_UPLOAD If that doesn't work, put verbose mode on and see what's going on: CURLOPT_VERBOSE -- Postgresql & php tutorials http://www.designmagick.com/$file = $dir."".$dbfile[0]; $this->invoiceno = $dbfile[1]; $uploadpath = "http://www.website.com; $postvar = array (); $postvar['cboFileType'] = "837"; $postvar['txtDesc'] = "Invoice No. ".$this->invoiceno; $postvar['btnSave'] = "Upload File"; $postvar['FILE1'] = "@$file"; $postvar['UPLOADING'] = "true";$this->postvariables = "txtUserName=".$this->user."&txtPassword=".$this->password."&btnLogin=Log In";// login first $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->login_post); curl_setopt($ch, CURLOPT_USERAGENT, $this->agent); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postvariables); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_REFERER, $this->reffer); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_file_path); $results = curl_exec ($ch); // upload file curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$postvar); curl_setopt ( $ch, CURLOPT_URL, $uploadpath); $uploaded = curl_exec ( $ch ); echo $uploaded;I think my problem is that the file I need to upload is not in the same directory on the server as this script. I am setting $file = /var/www/include/upload/test.txt and this is what seems to be causing the problem. I can find very little information on this topic on google so I need your help. Do I need to copy the file to the same directory that the script is in or is there something else I am missing? If I just set $file = test.txt how would the server know where to find the file?