Script upload ftp:
Codice PHP:
<?php
$local_path = "/membri/tecnoman/php5/"; //percorso del file da mandare
$file_name = "visite.txt"; //fnome del file
$ftp_user = 'tecnoman'; // ftp username
$ftp_pass = '***************'; // ftp password
$ftp_location = "ftp.tecnoman.altervista.org/"; // ftp destinazione
$http_path = "php5/files/"; // cartella destinazione
//server script
$server_script_url = "http://tecnoman.altervista.org/php5/testscript.php";
$fileToSend = $local_path.$file_name;
$ftp_url = "ftp://".$ftp_user.":".$ftp_pass."@".$ftp_location.$http_path.$file_name;
$errorMsg = '';
// ------- Upload con FTP ---------------
if (is_file($fileToSend)){
$ch = curl_init();
$fp = fopen ($fileToSend, "r");
// upload del file txt
curl_setopt($ch, CURLOPT_URL, $ftp_url);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
// imposta la grandezza
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($fileToSend));
$res = curl_exec ($ch);
$errorMsg = curl_error($ch);
$errorNumber = curl_errno($ch);
curl_close ($ch);
// avvia loscript sul server con il nome del file da uploadare
if ($errorNumber==0){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server_script_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'fileuploaded='.$http_path.$file_name);
$res = curl_exec ($ch);
$errorMsg = curl_error($ch);
$errorNumber = curl_errno($ch);
curl_close ($ch);
echo $res; //DEBUG
}
if ($errorNumber>0){
print 'Errore CURL: '.$errorMsg." - n.".$errorNumber; // DEBUG
}
}
else{
print 'Impossibile trovare il file:'.$fileToSend; // DEBUG
}
?>
Script di verifica:
Codice PHP:
<?php
$res = "ERRORE";
if (!empty($_POST['fileuploaded'])){
$filename = $_SERVER['DOCUMENT_ROOT'].$_POST['fileuploaded'];
if (is_file($filename)){
$handle = fopen ($filename, "r");
$res = fread($handle, filesize($filename));
fclose($handle);
}
}
print $res;
?>