Home Menu

curl_file_create

Create a CURLFile object

Syntax

curl_file_create ( string $filename [, string $mimetype = "" [, string $postname = "" ]] ) : CURLFile

Parameters

filename

Path to the file which will be uploaded.

mimetype

Mimetype of the file.

postname

Name of the file to be used in the upload data.

Return

Returns a CURLFile object.

Examples

1

<?

$ch = curl_init();

    $filename = 'dogs.jpg';
    $mimetype = 'image/jpeg';
    $postname = 'test_name';

    $return = curl_file_create($filename, $mimetype, $postname);

    curl_setopt($ch, CURLOPT_URL, "https://php.net/upload.php");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('test_file' => $return));
    
    curl_exec($ch);
    
curl_close($ch);

?>

			
			

		

2

<?

$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "https://php.net/upload.php");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,
    [
        'blob[0]' => curl_file_create(realpath('first-file.jpg'), 'image/jpeg'),
        'blob[1]' => curl_file_create(realpath('second-file.txt'), 'text/plain'),
        'blob[2]' => curl_file_create(realpath('third-file.exe'), 'application/octet-stream'),
    ] );

    curl_exec($ch);
    
curl_close($ch);

?>

			
			

		

PHP

JesusBible
HTMLCSSJSPHPSVGMore
AboutTerms