Jump to content

Why Not Getting The Write Error Message Based On The IF Condition ?


phpsane

Recommended Posts

On 9/8/2018 at 9:31 AM, phpsane said:

Which one of these 2 I should stick to ?

mkdir("$directory_path" . "$user", "$mode", TRUE);  //Originally I had it like this. That param inputs should be inside dbl quotes.

mkdir($directory_path . $user . $mode, TRUE);  // I now reckon, I should stick to this. Param inputs should not be quoted atall. be it sngl quote or dbl. What you say ?

Correct.  This is what was told to you initially when this was brought up.  You don't need the double quotes UNLESS you are trying to INTERPOLATE the variables together into one or more strings. 

I showed you how you could get to the same result (concatenating multiple string variables and/or string constants together using '.'  OR

Using INTERPOLATION  (Variables and string constant snippets inside of " ".

Also -- because code compiles (doesn't create an error) does not mean that it is CORRECT.  Mkdir is looking for a STRING that represents the correct path to the directory you want to create.  If you feed it this input:

$user = 'bob smith';
mkdir('O M G $ 779/' . '$user', 0777, TRUE); 

Then the final path variable is going to be 'O M G $ 779/$user'

That is a string.  It might even be accepted by the operating system as a legitimate path, and you may end up with a directory created:  O M G $ 779/

And inside of it will be another directory: $user

That might work, but it certainly isn't what you intended.  

I also think you should note, that you should always check the result of an operation like mkdir() because otherwise you have no idea if it worked or not.

if (mkdir('O M G $ 779/' . '$user', 0777, TRUE)) {
  // Proceed

} else {
    echo "Unable to create the Directory";
}

 

Link to comment
Share on other sites

On 9/8/2018 at 5:31 PM, phpsane said:

mkdir($directory_path . $user . $mode, TRUE);  // I now reckon, I should stick to this. Param inputs should not be quoted atall. be it sngl quote or dbl. What you say ?

That is correct ony in the removal of the quotes. However your inabilty to distinguish beween a "." and a "," makes it incorrect.

Try

mkdir($directory_path . $user , $mode, TRUE); 

 

Link to comment
Share on other sites

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.