What is the difference between manually uploading a file using a console command and using PHP with cURL for API upload?

Manually uploading a file using a console command typically involves using tools like cURL or FTP to send the file to a server. On the other hand, using PHP with cURL for API upload allows for programmatically sending files to a server using HTTP requests. This method is more flexible and can be integrated into web applications or scripts.

<?php
$filePath = '/path/to/file.txt';
$uploadUrl = 'https://api.example.com/upload';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uploadUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
    'file' => new CURLFile($filePath)
]);

$response = curl_exec($ch);

if($response === false) {
    echo 'Error: ' . curl_error($ch);
} else {
    echo 'File uploaded successfully!';
}

curl_close($ch);
?>