Jump to content

Recommended Posts

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  ;D

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...

Link to comment
https://forums.phpfreaks.com/topic/155390-pathdirectory-joining-issues/
Share on other sites

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.

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.

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.