Uploading Files Using PHP

This is a sample of PHP script uploading files to the Panel. Change HOST, LOGIN, PASSWD, and FILENAME with Plesk credentials.

 

HOST

The IP address or name of the Panel-managed server.

LOGIN

Login name of the Panel administrator.

PASSWD

Password of the Panel administrator.

FILENAME

Full name of the file to be uploaded.

 

<?php
define("HOST", "10.58.97.31");
define("PATH", "/enterprise/control/agent.php");
define("LOGIN", "admin");
define("PASSWD", 'setup');
define("FILENAME", '../../data.rpm');
 
function write_callback($ch, $data)
{
echo $data;
return strlen($data);
}
 
function uploadFile($filename)
 
{$url = "https://" . HOST . ":8443" . PATH;
 
$headers = array(
"HTTP_AUTH_LOGIN: " . LOGIN,
"HTTP_AUTH_PASSWD: " . PASSWD,
"HTTP_PRETTY_PRINT: TRUE",
"Content-Type: multipart/form-data;",
);
 
// Initialize the curl engine
$ch = curl_init();
 
// Set the curl options
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
// this line makes it work under https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 
// Set the URL to be processed
curl_setopt($ch, CURLOPT_URL, $url);
 
curl_setopt($ch, CURLOPT_POSTFIELDS, array
('sampfile'=>"@$filename"));
 
$result = curl_exec($ch);
 
if (curl_errno($ch)) {
echo "\n\n-------------------------\n" .
"cURL error number:" .
curl_errno($ch);
echo "\n\ncURL error:" . curl_error($ch);
}
 
curl_close($ch);
 
//fclose($fp);

return;
}
 
uploadFile(realpath(FILENAME));
 
?>
 

Leave your feedback on this topic here

If you have questions or need support, please visit the Plesk forum or contact your hosting provider.
The comments below are for feedback on the documentation only. No timely answers or help will be provided.