X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=api.php;h=521d20b0d1cdcc9b958347a0cfe56b2c95877926;hp=50e8bfe3cfa2cc5cc1fad902cc24cde9757d03e8;hb=ec0e87c5345c39b2317fed18338681621460159d;hpb=4acc8da49e3d4083fd9906388dd8fe0212bb9f42 diff --git a/api.php b/api.php index 50e8bfe..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,8 +128,9 @@ function save_uploaded_file ($file, $con) { (!move_uploaded_file ($file ["tmp_name"], $dest))) { server_error (); } + send_to_ftp ($dest); } - return basename($dest); + return basename_safe ($dest); } function img_check_upload ($file) { @@ -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; @@ -148,7 +180,7 @@ function unique_file ($dirname, $relpath, $con) { while ($counter < 1000) { if (!file_exists ($filename) && - !($con->imgpath_exists (basename ($filename)))) { + !($con->imgpath_exists (basename_safe ($filename)))) { return $filename; } else { $counter++;