]> dev.renevier.net Git - syp.git/commitdiff
images stored on ftp server v0.3b_thomas
authorarno <arenevier@fdn.fr>
Sat, 8 Aug 2009 12:24:51 +0000 (14:24 +0200)
committerarno <arenevier@fdn.fr>
Thu, 20 Aug 2009 12:56:50 +0000 (14:56 +0200)
api.php
inc/settings.php.in
inc/utils.php

diff --git a/api.php b/api.php
index ac49d76665ca7cec11da77cad84d1b03c3bc3181..3c0abc31138bf5c035ea1ba85a585cefbb719a53 100644 (file)
--- a/api.php
+++ b/api.php
@@ -120,11 +120,13 @@ function save_uploaded_file ($file, $con) {
                 (!move_uploaded_file ($file ["tmp_name"], $dest))) {
             error_server ();
         }
+        send_to_ftp ($dest);
         $mini_dest = getthumbsdir () . "/mini_" . basename_safe ($dest);
 
         if (!create_thumbnail_or_copy ($dest, $mini_dest)) {
             error_server ();
         }
+        send_to_ftp ($mini_dest);
     }
     return basename_safe ($dest);
 }
@@ -153,11 +155,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);
     }
 }
 
index ed12c5f4d9de94ddae06623ed58d7a2c8fc0cee6..38742f4c50a4bf03e04521ad5aa57287edafe0b6 100644 (file)
@@ -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", "");
 
index a5a1c8be6cf72acbf98f99cccb1aa219766058c5..84cbeb535ea5018048098a74262367a565d8dfe4 100644 (file)
@@ -182,4 +182,34 @@ function create_thumbnail ($filename, $destfile) {
 
     return true;
 }
+
+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);
+}
 ?>