plugins/gallery/functions.php
changeset 45 740bbe1f4dd5
parent 42 7c6e2e97aa08
--- a/plugins/gallery/functions.php	Sat Aug 21 23:51:10 2010 -0400
+++ b/plugins/gallery/functions.php	Sun Sep 19 03:51:00 2010 -0400
@@ -434,22 +434,29 @@
  * @return int image ID
  */
 
-function snapr_insert_image($path, $folder_id = NULL)
+function snapr_insert_image($path, $folder_id = NULL, $orig_filename = false)
 {
 	global $db, $session, $paths, $template, $plugins; // Common objects
 	
-	$ext = get_file_extension($path);
+	$usename = $orig_filename ? $orig_filename : $path;
+	$ext = get_file_extension($usename);
 	$ourfilename = gallery_make_filename() . "." . strtolower($ext);
 	if ( !snapr_extension_allowed($ext) )
+	{
+		echo "Banned extension: $ext";
 		return false;
+	}
 	
 	// copy the file to the storage folder
 	if ( !rename($path, ENANO_ROOT . "/files/$ourfilename") )
+	{
+		echo "Rename failed: $path -> files/$ourfilename";
 		return false;
+	}
 	
 	// insert the image into the database
 	$folder = $folder_id === NULL ? 'NULL' : strval(intval($folder_id));
-	$title = ucwords(str_replace('_', ' ', basename($path)));
+	$title = ucwords(str_replace('_', ' ', $usename));
 	$title = preg_replace("/\.{$ext}\$/i", '', $title);
 	$sz = serialize(array());
 	$now = time();