Jump to content

cURL Upload Help


savagenoob

Recommended Posts

OK, I am creating a bridge from a local program to my website and I am trying to find the best way to upload the client file from the local program (which is a CSV file) to my server. I was thinking I could use cURL to accomplish this feat. Basically the local program will invoke a batch file that opens my site with the path of the local file (which is the same file name and path everytime), then use cURL to upload that file to my server to be parsed and input into the database. Can this be done?

If so, I would have to just point the cURL to the .php file that would accept the uploaded file correct? And could I use POST for this with multi-form data and not PUT? Any input on this would be great, thanks.

Maybe something similar to this...

   $file='testWordDoc.doc'; 

    echo $file; 
     
    $ch = curl_init('http://myurl.com/recieve_posted.php');   
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('file'=>"@$file",'testkey'=>'test value')); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $postResult = curl_exec($ch); 
    curl_close($ch); 
    print "$postResult"; 

Link to comment
https://forums.phpfreaks.com/topic/187851-curl-upload-help/
Share on other sites

OK, so something like this

<?php
// set up basic connection
$conn_id = ftp_connect($ftp_server); 

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

// check connection
if ((!$conn_id) || (!$login_result)) { 
        echo "FTP connection has failed!";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
        exit; 
    } else {
        echo "Connected to $ftp_server, for user $ftp_user_name";
    }

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 

// check upload status
if (!$upload) { 
        echo "FTP upload has failed!";
    } else {
        echo "Uploaded $source_file to $ftp_server as $destination_file";
    }

// close the FTP stream 
ftp_close($conn_id); 
?> 

 

And the source file can be on the local computer of the user and not on the webserver? I was only thinking of cURL to spoof a form as if the user selected their own local file to upload to server.

Link to comment
https://forums.phpfreaks.com/topic/187851-curl-upload-help/#findComment-991820
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.