notos
January 6th, 2005, 06:30 AM
i am making a scrtip that takes a screen from your desktop conects to your FTP and uploads it an a thumb and youi know what it Works!!!!! ... but only when i run it when it is run by cron it gives me an errer "can not conect to X server" :(
i put the code here it is programed with PHP(Cli)
actualy te line that gives error is
import -window root $local_file
#!/usr/local/bin/php
<?php
##############################
# (c) by notos | julianduenas@gmail.com #
# this Script is under the Gnu/GPL #
##############################
# configuration
$ftp_server = 'server.com';
$ftp_port = 21;
$ftp_user = 'user';
$ftp_pass = 'pass';
$ftp_dir = '/public_html/screens';
# image type
$ext = 'png';
# Edit this only if you know what are you doing
$local_file = "/tmp/current.$ext";
$local_thumb = '/tmp/current_thumb.'.$ext;
exec("import -window root $local_file");
exec("convert -sample 25%x25% $local_file $local_thumb");
$image = fopen($local_file, 'r');
$image_thumb = fopen($local_thumb, 'r');
$file = $ftp_dir.'/current.'.$ext;
$file_thumb = $ftp_dir.'/current_thumb.'.$ext;
$ftp_id = ftp_connect($ftp_server,$ftp_port) or die('error');
$ftp_login = ftp_login($ftp_id,$ftp_user,$ftp_pass);
function upload_current()
{
global $ftp_id,$image_thumb,$file_thumb,$image,$file,$loc al_file,$local_thumb;
if (ftp_fput($ftp_id, $file_thumb, $image_thumb, FTP_BINARY)) {
echo "Successfully uploaded $file_thumb\n";
} else {
echo "There was a problem while uploading $file\n";
}
if (ftp_fput($ftp_id, $file, $image, FTP_BINARY)) {
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
unlink($local_file);
unlink($local_thumb);
}
if (!file_exists('LOCAL'))
{
ftp_mkdir($ftp_id,$ftp_dir);
ftp_mkdir($ftp_id,$ftp_dir."/archive");
fopen('LOCAL','x');
upload_current();
}
else
{
$time = date('Y-m-d-H_i_s');
ftp_rename($ftp_id,$ftp_dir."/current.$ext",$ftp_dir."/archive/$time.$ext");
ftp_rename($ftp_id,$ftp_dir."/current_thumb.$ext",$ftp_dir."/archive/".$time."_thumb.".$ext."");
upload_current();
}
ftp_close($ftp_id);
exit(0);
?>
i put the code here it is programed with PHP(Cli)
actualy te line that gives error is
import -window root $local_file
#!/usr/local/bin/php
<?php
##############################
# (c) by notos | julianduenas@gmail.com #
# this Script is under the Gnu/GPL #
##############################
# configuration
$ftp_server = 'server.com';
$ftp_port = 21;
$ftp_user = 'user';
$ftp_pass = 'pass';
$ftp_dir = '/public_html/screens';
# image type
$ext = 'png';
# Edit this only if you know what are you doing
$local_file = "/tmp/current.$ext";
$local_thumb = '/tmp/current_thumb.'.$ext;
exec("import -window root $local_file");
exec("convert -sample 25%x25% $local_file $local_thumb");
$image = fopen($local_file, 'r');
$image_thumb = fopen($local_thumb, 'r');
$file = $ftp_dir.'/current.'.$ext;
$file_thumb = $ftp_dir.'/current_thumb.'.$ext;
$ftp_id = ftp_connect($ftp_server,$ftp_port) or die('error');
$ftp_login = ftp_login($ftp_id,$ftp_user,$ftp_pass);
function upload_current()
{
global $ftp_id,$image_thumb,$file_thumb,$image,$file,$loc al_file,$local_thumb;
if (ftp_fput($ftp_id, $file_thumb, $image_thumb, FTP_BINARY)) {
echo "Successfully uploaded $file_thumb\n";
} else {
echo "There was a problem while uploading $file\n";
}
if (ftp_fput($ftp_id, $file, $image, FTP_BINARY)) {
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
unlink($local_file);
unlink($local_thumb);
}
if (!file_exists('LOCAL'))
{
ftp_mkdir($ftp_id,$ftp_dir);
ftp_mkdir($ftp_id,$ftp_dir."/archive");
fopen('LOCAL','x');
upload_current();
}
else
{
$time = date('Y-m-d-H_i_s');
ftp_rename($ftp_id,$ftp_dir."/current.$ext",$ftp_dir."/archive/$time.$ext");
ftp_rename($ftp_id,$ftp_dir."/current_thumb.$ext",$ftp_dir."/archive/".$time."_thumb.".$ext."");
upload_current();
}
ftp_close($ftp_id);
exit(0);
?>