X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=inc%2Futils.php;h=068f6d6f185dde8a907736a5ff6331f8725efcf3;hp=12c85c673dfd321a9b1d1a955103aa93f5895d2c;hb=80e63e12e3043d7164c35c4babd830dd969cd212;hpb=9acc365249b5e630da6b5cdd23e3a8015f39ddc7 diff --git a/inc/utils.php b/inc/utils.php index 12c85c6..068f6d6 100644 --- a/inc/utils.php +++ b/inc/utils.php @@ -45,7 +45,7 @@ function unquote($gpc_str) { function thumb_url_from_imgpath ($filename) { if (defined ("THUMBSDIRURL") && (strlen (THUMBSDIRURL) != 0)) { - return rtrim (THUMBSDIRURL, '/') . "/_mini" . rawurlencode ($filename); + return rtrim (THUMBSDIRURL, '/') . "/mini_" . rawurlencode ($filename); } return full_url_from_path (getthumbsdir () . "/mini_" . rawurlencode ($filename)); } @@ -101,7 +101,25 @@ function full_url_from_path ($path) { return "$proto://$host$port$path"; } +function create_thumbnail_or_copy ($filename, $destfile) { + try { + $thumbnail_ok = create_thumbnail ($filename, $destfile); + } catch (Exception $e) { + $thumbnail_ok = false; + } + if (!$thumbnail_ok) { + if (!copy ($filename, $destfile)) { + return false; + } + } + return true; +} + function create_thumbnail ($filename, $destfile) { + if (!function_exists ("imagecreatefromjpeg") + || !function_exists ("imagecreatefrompng")) { + return false; + } $ext = strtolower (ext_safe ($filename)); if ($ext == "jpg" || $ext == "jpeg") { $image = imagecreatefromjpeg ($filename); @@ -184,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"); }