Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6916003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:32:48+00:00 2026-05-27T09:32:48+00:00

From bash terminal, I successfully executed the following command. curl -v -L -F file=’@/var/www/dev/public_html/sixties.mov’

  • 0

From bash terminal, I successfully executed the following command.

curl -v -L -F file='@/var/www/dev/public_html/sixties.mov' -F title='my video' -F description='this is a video' -F language='eng' -F license='a2be14e1-37d9-11dd-ae16-0800200c9a66' -F country='US' http://johnuser:johnpass@website.com/api/media

Now I want to create a PHP script that uses the phpcurl library to execute an equivalent command. My code below is shown, but it’s not working. The http://johnuser:johnpass@website.com/api/media server is giving me a generic error message. I’m pretty sure I’m making a mistake by not passing the right parameters or setting the right flags in my php code. Can anyone tell me what’s wrong?

$url = 'http://johnuser:johnpass@website.com/api/media';

$fields = array();
$fields['file'] = '@/var/www/dev/public_html/sixties.mov';
$fields['title'] = 'my video';
$fields['description'] = 'this is a test';
$fields['language'] = 'eng';
$fields['country'] = 'US';
$fields['license'] = 'a2be14e1-37d9-11dd-ae16-0800200c9a66';

foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');

$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);
print_r($result);

The error message I got is {"status":{"message":"typeMismatch ","error":true,"code":500}}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:32:49+00:00Added an answer on May 27, 2026 at 9:32 am

    I think this is what you need to be doing, if you want upload a file:

    // Parameters
    $url = 'http://website.com/api/media';
    $username = 'johnuser';
    $password = 'johnpass';
    $upload_file = '/var/www/dev/public_html/sixties.mov';
    
    // Declare a couple of arrays we will need
    $fields = $headers = array();
    
    // Standard POST fields
    $fields['title'] = 'my video';
    $fields['description'] = 'this is a test';
    $fields['language'] = 'eng';
    $fields['country'] = 'US';
    $fields['license'] = 'a2be14e1-37d9-11dd-ae16-0800200c9a66';
    
    // Boundary string for multipart message
    $boundary = '--=-=-'.md5(uniqid()).rand().'-=-=--';
    
    // Start the body with the file to be uploaded
    $body = "--$boundary\r\n"
          . "Content-Disposition: form-data; name=\"file\"; filename=\"".basename($upload_file)."\"\r\n"
          . "Content-Type: application/octet-stream\r\n" // You should put the right MIME type here
          . "\r\n"
          . file_get_contents($upload_file) . "\r\n";
    
    // Loop the fields and build the rest of the body
    foreach ($fields as $name => $value) {
      $body .= "--$boundary\r\n"
             . "Content-Disposition: form-data; name=\"$name\"\r\n"
             . "\r\n"
             . "$value\r\n";
    }
    
    // Finish the body
    $body .= "--$boundary--";
    
    // Add a couple of headers
    $headers[] = "Content-Type: multipart/form-data; boundary=\"$boundary\"";
    $headers[] = 'Content-Length: ' . strlen($body);
    
    $ch = curl_init();
    
    // Set the cURL options
    curl_setopt($ch, CURLOPT_URL,            $url);
    curl_setopt($ch, CURLOPT_USERPWD,        "$username:$password");
    curl_setopt($ch, CURLOPT_POST,           TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS,     $body);
    curl_setopt($ch, CURLOPT_HTTPHEADER,     $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    
    // Execute post
    $result = curl_exec($ch);
    
    // Close connection
    curl_close($ch);
    print_r($result);
    

    POST file uploads are done with a MIME multipart message, using the multipart/form-data sub-type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following command issued from a terminal gets me yesterday's date: date --date='1 day
Using mysql directly from the command line (running on Ubuntu 9.10, standard bash terminal),
I need to read a value from the terminal in a bash script. I
Currently I'm doing some unit tests which are executed from bash. Unit tests are
I try to get to a page straight from Bash at http://www.ocwconsortium.org/ . The
I am sourcing a file in a bash terminal that needs to export some
How do I FTP GET this file from a Unix terminal? ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz My attempts:
I'm trying to open a file using MacVim 7.3 (53) from the command line
I am trying to make a bash script that will transfer a file from
Does anyone know of a way to read in terminal output from bash commands

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.