From ec0e87c5345c39b2317fed18338681621460159d Mon Sep 17 00:00:00 2001 From: arno Date: Sun, 26 Jul 2009 17:43:55 +0200 Subject: [PATCH] images are stored on a ftp server --- api.php | 32 ++++++++++++++++++++++++++++++++ inc/settings.php | 12 ++++++++++++ 2 files changed, 44 insertions(+) diff --git a/api.php b/api.php index 39c6319..521d20b 100644 --- a/api.php +++ b/api.php @@ -89,6 +89,36 @@ function notanimage_error () { error ("notimage"); } +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", FTPIMGDIR, basename ($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", FTPIMGDIR, basename ($file)); + $upload = ftp_put ($ftp_conn, $dest, $file, FTP_BINARY); + + if (!$upload) { + server_error (); + } + ftp_close ($ftp_conn); +} + function save_uploaded_file ($file, $con) { $dest = ""; if (isset ($file) && ($file ["error"] != UPLOAD_ERR_NO_FILE)) { @@ -98,6 +128,7 @@ function save_uploaded_file ($file, $con) { (!move_uploaded_file ($file ["tmp_name"], $dest))) { server_error (); } + send_to_ftp ($dest); } return basename_safe ($dest); } @@ -125,6 +156,7 @@ function delete_image_if_unused ($imgpath, $con) { $path = UPLOADDIR . "/" . $imgpath; if (file_exists($path)) { unlink ($path); + delete_from_ftp ($path); return true; } else { return false; diff --git a/inc/settings.php b/inc/settings.php index 3f3a358..0cc5a29 100644 --- a/inc/settings.php +++ b/inc/settings.php @@ -24,6 +24,18 @@ define ("UPLOADDIR", "upload"); // title of your website define ("SITETITLE", "SYP"); +// ftp server to store photos +define ("FTPSERVER", ""); + +// ftp user +define ("FTPUSER", ""); + +// ftp pass +define ("FTPPASS", ""); + +// ftp directory +define ("FTPIMGDIR", ""); + // email contact for webmaster. define ("WEBMASTERMAIL", ""); -- 2.39.5