Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • upload file using CURL?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 195
    Comment on it

    As we know that CURL is a library that allow us to make requests(HTTP requests) in PHP.

    We can upload a file as well using CURL. For upload a file using CURL must follow below points :

    1. Uploading file size is mandatory to be less than file allowed by the Server.

    2. If file size is too big , then it may take a bit more time.

    3. Please replace "uploadFile.zip" named file with the file which you want for uploading. and it should addressed with full path.
    4. replace "http://localhost/test/index2" with that URL for which server has given the functionality for upload file.

       $file_name_with_full_path = realpath('uploadFile.zip');        
       $url = "http://localhost/test/index2";
       $post_data = array(
                   "foo" => "bar",
                     "upload" => "@".$file_name_with_full_path
                 );
        try {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
            $output = curl_exec($ch);
            curl_close($ch);
      

      } catch (Exception $e) { echo $e->getMessage(); die; }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: