SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,045
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP upload file using CURL()

    Hi Guys!

    I am trying to upload a file to another server using CURL..Here's the script that uploads the file from the input server. How do I create the script on the receiving server? For example, I need to move the uploaded file into a folder.

    How do I do that?

    PHP Code:
    function UploadCV2(){
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_HEADER0);
        
    curl_setopt($chCURLOPT_VERBOSE0);
        
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
    curl_setopt($chCURLOPT_USERAGENT$_SERVER['HTTP_USER_AGENT']);
        
    curl_setopt($chCURLOPT_URL"http://www.mydomain.com/parse.php");
        
    curl_setopt($chCURLOPT_POST1);
        
    curl_setopt($chCURLOPT_POSTFIELDS"key=YT567BZX9W21DVLK&clientdomain=mydomain.co.uk&cvfile=@".$_FILES['cv']['tmp_name']); 
        
    $response curl_exec($ch);
        
    $errnum curl_errno($ch);
        
        echo 
    $response; exit;


  2. #2
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two things come to mind off the top of my head. They could be complete nonsense, but here goes.

    1. Your uploading script on server A could call a script on the other server (B) and use URL vars to trigger the remote script. I've never tried this with curl, so I have no idea if it will work.

    For instance, your script on server B (the server being uploaded to) could have a line such as: if($_GET['uploaded'] == true && file_exists($path_to_file)) which then triggers the script to move the uploaded file.

    Or, instead of using curl to trigger the script, you could issue a header redirect after the script has finished uploading, which will then trigger the remote script via a browser, giving it a greater chance of working.


    2. Use a cron job on server B to check the directory every x minutes and move the file if it exists. This one should definitely work since you're not doing anything remotely.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •