sader Posted April 23, 2009 Share Posted April 23, 2009 Hi guys I am doing image upload function for my application, it works but the way it's done I don't like very much. The thing is that I mest up with path seperators. In my datebase I heve setting called image_upload_directory value = "uploads\images\" so this format is correct in my case but if it's setted to "\uploads\images\" or "\uploads\images" everything is mest up cuz those slashes at the end or begining are meaningful, so I must be very careful and accurate with it :-\ Let's look what if I try join this string with getcwd()."uploads\images\", it becomes even more worse "C:/root/bb/\uploads\usermimes\". Ok what about saving joined string to database? It becomes something like "uploads/images//image001.gif" or "\uploads/images///image001.gif" And here u go there is DIRECTORY_SEPARATOR & PATH_SEPARATOR constants So they want to tell me that every server may set his own seperator? Omg... Will my normal inludes work, or should I include("classes".DIRECTORY_SEPARATOR."classA.php") <= I really dont' want do that if server is using for example '@' as directory seperator? And this is only on Windows OS what will heppen on Unix? As You can see I found meny thigs disturbing, and this is not first and not last time when I need to join directory name from seperate chunks. So I am asking maybe someone from you knows neat way to handle these "joining" variations or maybe just could explane what is correct seperator or correct rules or soemthing... Quote Link to comment https://forums.phpfreaks.com/topic/155390-pathdirectory-joining-issues/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 23, 2009 Share Posted April 23, 2009 Windows versions of php convert / to \ before passing the path to operating system calls. So, just always use / Quote Link to comment https://forums.phpfreaks.com/topic/155390-pathdirectory-joining-issues/#findComment-817587 Share on other sites More sharing options...
wildteen88 Posted April 23, 2009 Share Posted April 23, 2009 I always use / as my directory separator regardless of the OS the script will be running on. However if you're going to use \ then define your paths within single quotes instead, eg include 'path\to\script'; With single quotes escape characters are not parsed. Quote Link to comment https://forums.phpfreaks.com/topic/155390-pathdirectory-joining-issues/#findComment-817589 Share on other sites More sharing options...
jonsjava Posted April 23, 2009 Share Posted April 23, 2009 kinda my thought on it too. you use "\" for escape characters. Example: \n = "new line" \t = "tab" \r = "carrier return" also, if you are echoing something, and you want it echoed verbatim, you use the "\": <?php echo "$test"; ?> will get you "Notice: <FILENAME> line 2 - Undefined Variable: test" while <?php echo "\$test"; ?> will print "$test" to the screen. Quote Link to comment https://forums.phpfreaks.com/topic/155390-pathdirectory-joining-issues/#findComment-817592 Share on other sites More sharing options...
sader Posted April 23, 2009 Author Share Posted April 23, 2009 Re:jonsjava that is exactly one of those annoying problems Firstly as u guys have suggested I changed all \ to / then I experimented a bit and here's what I find out. Extra "/" at the begining of string was BAD and function move_uploaded_file() failed, but for example any count of "/" one by one(Ex: "//////////") will be interpretated as legal seperator so for example path "uploads/////images/image001.gif" is correct. Not sure how correct is that, but at least I was able to see my picture. Anyway what about those DIRECTORY_SEPARATOR, PATH_SEPARATOR? Are they useful, in what cases I should bother about them? btw: PATH_SEPARATOR echoed ; what for is that one? Tnx for advices. Quote Link to comment https://forums.phpfreaks.com/topic/155390-pathdirectory-joining-issues/#findComment-817687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.