From 80e63e12e3043d7164c35c4babd830dd969cd212 Mon Sep 17 00:00:00 2001 From: arno Date: Sat, 8 Aug 2009 14:24:51 +0200 Subject: [PATCH] images stored on ftp server --- api.php | 4 ++++ inc/settings.php | 12 ++++++++++++ inc/utils.php | 30 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/api.php b/api.php index 2054350..302c1c7 100644 --- a/api.php +++ b/api.php @@ -98,11 +98,13 @@ function save_uploaded_file ($file, $con) { (!move_uploaded_file ($file ["tmp_name"], $dest))) { server_error (); } + send_to_ftp ($dest); $mini_dest = getthumbsdir () . "/mini_" . basename_safe ($dest); if (!create_thumbnail_or_copy ($dest, $mini_dest)) { server_error (); } + send_to_ftp ($mini_dest); } return basename_safe ($dest); } @@ -131,11 +133,13 @@ function delete_image_if_unused ($imgpath, $con) { $path = UPLOADDIR . "/" . $imgpath; if (file_exists ($path)) { unlink ($path); + delete_from_ftp ($path); } $thumb_path = getthumbsdir () . "/mini_" . $imgpath; if (file_exists ($thumb_path)) { unlink ($thumb_path); + delete_from_ftp ($thumb_path); } } diff --git a/inc/settings.php b/inc/settings.php index 5d4910a..c06b92d 100644 --- a/inc/settings.php +++ b/inc/settings.php @@ -28,6 +28,18 @@ define ("THUMBSDIR", "upload/_thumbs"); // title of your website define ("SITETITLE", "SYP"); +// ftp server to store photos +define ("FTPSERVER", ""); + +// ftp user +define ("FTPUSER", ""); + +// ftp pass +define ("FTPPASS", ""); + +// ftp directory for images and thumbnails +define ("FTPROOTDIR", ""); + // email contact for webmaster. define ("WEBMASTERMAIL", ""); diff --git a/inc/utils.php b/inc/utils.php index b093b0b..068f6d6 100644 --- a/inc/utils.php +++ b/inc/utils.php @@ -202,6 +202,36 @@ function safe_create_writable_dir ($dirname) { } } +function delete_from_ftp ($file) { + $ftp_conn = ftp_connect (FTPSERVER); + $login = ftp_login ($ftp_conn, FTPUSER, FTPPASS); + if ((!$ftp_conn) || (!$login)) { + server_error (); + } + $target = sprintf ("%s/%s", FTPROOTDIR, $file); + $deleted = ftp_delete ($ftp_conn, $target); + + if (!$deleted) { + server_error (); + } + ftp_close ($ftp_conn); +} + +function send_to_ftp ($file) { + $ftp_conn = ftp_connect (FTPSERVER); + $login = ftp_login ($ftp_conn, FTPUSER, FTPPASS); + if ((!$ftp_conn) || (!$login)) { + server_error (); + } + $dest = sprintf ("%s/%s", FTPROOTDIR, $file); + $upload = ftp_put ($ftp_conn, $dest, $file, FTP_BINARY); + + if (!$upload) { + server_error (); + } + ftp_close ($ftp_conn); +} + function leave () { exit ("\n"); } -- 2.39.2