Page 1 of 1

bug in image paths

Posted: Sat Mar 04, 2006 7:12 pm
by SHRIKEE
Hi all,

Yes the terrible SHRIKEE has something to complain again! :shock:

While working on usergallery plugin mgroeninger found a bug in the paths of s9y. When a file is saved in a subfolder some / become //.

He also made a quick workaround for usergallery to deal with this. Assuming it was fixed. Sadly it was not. When i got the code from him and tested it on my server it apeared that the // caused usergallery to malfunction. Even removing mgroeninger's fix did not solve the problem. So here i am. Crying for a patch.

in short:
when uploading an image to a subfolder using the media library the paths are messed up with // where it should be /

Posted: Sat Mar 04, 2006 11:02 pm
by mgroeninger
SHRIKEE, I got your email but I figure working on this here will be easier than trying to co-ordinate a bunch of different emails...

Garvin, sometime in the next few days I will sit down and try to trace this issue... (Or at least write a full bug report of what I am seeing.)

If you know of something that might cause it off the top of your head, I'd love any suggestions...

Essentially, in my two installs (One 0.9.1 and the other 1.0-beta1, running under apache 1.3.33 on windows, php 4.3.11) I am finding serendipity_traversePath will return paths with multiple backslashes for some subfolders below two levels. I don't know which subfolders or why they are a problem yet.

I believe the difference between SHRIKEE's problem and mine probably arise from different methods of adding the files. I used the "Rebuild Thumbs" link in the administrator, and I would bet money SHRIKEE used the standard form to add the images, which happens to use serendipity_traversePath output for the dropdown box. So I believe the problem is just in the relpath output from serendipity_traversePath.

Testing the addition of a picture to the database using the Add media page I receive this output:

Code: Select all

File what-I-would-use.jpg successfully uploaded as C:/serendipitypath/uploads/Alphie//Alphie1//test1/test2/what-I-would-use.jpg
Thumbnail created.
Done.

Note the double slashes between Alphie and Alphie1 and test1... That data is added to the database.

The check I used to test for this in input (in the usergallery plugin) is:

Code: Select all

$getpathtemp = str_replace("//","/",str_replace("..","",$_GET['gallery']));
(obviously this is also testing for dots in the path..)

I think perhaps a patch like (untested patch follows):

Code: Select all

Index: functions_images.inc.php
===================================================================
--- functions_images.inc.php	(revision 993)
+++ functions_images.inc.php	(working copy)
@@ -1619,7 +1619,7 @@
                     $files[] = array(
                         'name'      => $file,
                         'depth'     => $depth,
-                        'relpath'   => ltrim(str_replace('\\', '/', serendipity_dirSlash('end', $dir)) . basename($file) . ($bIsDir ? '/' : ''), '/'),
+                        'relpath'   => str_replace("//","/",ltrim(str_replace('\\', '/', serendipity_dirSlash('end', $dir)) . basename($file) . ($bIsDir ? '/' : ''), '/')),
                         'directory' => $bIsDir
                     );
                 }
would work, but certainly does not address the underlying cause. It also might break installs for anyone who is operating with this type of structure.

Posted: Sun Mar 05, 2006 4:46 pm
by SHRIKEE
Uploading files with ftp or similiar and rebuilding the thumbs indeed saves correct paths.

Posted: Sun Mar 05, 2006 9:01 pm
by garvinhicking
This has been addressed and fixed in Serendipity 1.1 already, where the media manager code has been altered in several places.

Having a "//" path however does NOT matter at all for a webserver, so this should not be any problem there; and code reading from the database could use a "LIKE 'blabla/%' code to fetch images?

Regards,
Garvin

Posted: Sun Mar 05, 2006 9:07 pm
by SHRIKEE
If it was just that simple...
In fact ive tried altering the query to use some thing along these lines

SELECT * FROM {prefix}images WHERE path LIKE '%$dirvariableofwhichiforgotthename%' ORDER BY $order $orderby

but that didnt work :(

*back to guildwars*

Posted: Mon Mar 06, 2006 9:19 am
by SHRIKEE
I just noticed that if there are spaces in a foldername the rebuild thumbs option goes nuts. and wont do anything with the images aswell as not adding them to the database.