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

Archived

This topic is now archived and is closed to further replies.

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