Recebe.php
De Cartola
Script "recebe.php", que recebe dados enviados via http.
<?
# cria pasta destino, se necessario
if (!empty($_POST['criapasta'])) {
if ( !file_exists($_POST['criapasta']) ) {
mkdir($_POST['criapasta'],0755,true);
}
if ( !file_exists($_POST['criapasta'] . "/recebe.php") ) {
copy("./recebe.php", $_POST['criapasta'] . "/recebe.php");
}
}
# verifica se arquivo ja existe
if (!empty($_GET['verifica'])) {
if ( file_exists($_GET['verifica']) ) {
print "ERRO";
} else {
print "OK";
}
exit;
}
# recebe arquivo
if (!empty($_POST['nome'])) {
$fh = fopen($_POST['nome'],"w");
$dados = base64_decode($_POST['conteudo']);
fwrite($fh,$dados);
$cmd = "md5sum " . $_POST['nome'] . " | awk '{print $1}'";
$md5 = system($cmd);
print $_POST['nome'] . " : $md5";
}
# junta pedacos se necessario
if (!empty($_POST['juntar'])) {
$cmd = "cat " . $_POST['juntar'] . ".* > " . $_POST['juntar'];
$execucao = system($cmd);
$cmd = "rm -f " . $_POST['juntar'] . ".*";
$execucao = system($cmd);
$cmd = "md5sum " . $_POST['juntar'] . " | awk '{print $1}'";
$md5 = system($cmd);
print $_POST['juntar'] . " : $md5";
}
# atualiza data do arquivo
if (!empty($_POST['touch'])) {
$cmd = "touch -t " . $_POST['ts'] . " " . $_POST['touch'];
$execucao = system($cmd);
}
?>