Support » Fixing WordPress » Curl Not Working in WordPress

  • Resolved swayam.tejwani

    (@swayamtejwani)


    I am facing an issue with uploading a file on another server using curl in wordpress, the code simply works outside wordpress, but when i use in a wordpress template then it throws an error “Error: couldn’t open file C:\wamp64\tmp\phpAFFB.tmp”
    I have wamp installed and apache maven which is having one java project, there is an api which allows me to upload file on this url “http://localhost:8080/fileupload/?projectName=project” which returns some string through which i identify that file has been uploaded.

    
    $tmpfile  = $_FILES['cvs_file']['tmp_name'];
    $filename = basename($_FILES['cvs_file']['name']); 
    $filetype = $_FILES['cvs_file']['type']; 
    
    	$post_data = array(
       'uploadingFiles' => curl_file_create($tmpfile, $filetype, $filename)
    	);
    
    $curl_handle = curl_init("http://localhost:8080/fileupload/?projectName=project");  
    curl_setopt($curl_handle, CURLOPT_POST, 1);
    curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $post_data); 
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER,FALSE);
    $returned_data = curl_exec($curl_handle);
    if( $returned_data === false ){
    	echo "Error: ". curl_error($curl_handle);
    }
    die;
    
    curl_close ($curl_handle);
    

    I have tried with wp_remote_post as well but file upload is not working, any help ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • “works outside wordpress” – are you using the same user to test as the user that WordPress is running as on the server? Looks like file permissions issue to me.

    Hey montrealist, thanks for your reply, its on my local server wampp, so the host username and password is same for both, not sure what permissions i need to set.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Curl Not Working in WordPress’ is closed to new replies.