I'm trying to get a directory made, after which a file is uploaded, the code looks a bit like this:
login[$inputs ['email'], $inputs ['password']] &&
mkdir['file/file/'.$_SESSION['user_id'].'/Profile', 0777, true] &&
logout[] &&
[if [move_uploaded_file[$_FILES["fileToUpload"]["tmp_name"], $target_file]] {
echo "The file ". htmlspecialchars[ basename[ $_FILES["fileToUpload"]["name"]]]. " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}]
However, if i use this snippit, i get the error code "Parse error: syntax error, unexpected token "if"", if i replace the "&&" with a semi-colon, the upload script will not execute! How do i make this work?
asked Feb 15 at 14:52
4
The code you provided doesn't seem to be complete, but to get the question answered: You don't have to write "if" inside another "if" condition.
// this
if [condition1 == true] {
if [condition2 == true] {}
}
// is the same as
if [condition1 == true && condition2 == true] {}
So the following is not needed and will most likely end in some kind of parsing error.
// the second "if" is not valid, you can keep the [], though
if [[condition1 == true] && if[condition2 == true]] {}
In order to clean this up you can of course nest these statements in functions, as you did with logout[] and call these functions and chain them with && or || operators.
function folderIsCreated[] {
return mkdir[...];
}
// function 2...
if [folderIsCreated[] && function2[] && function3[]] {}
Long story short for your code: Remove the if inside the if.
answered Feb 15 at 15:30
clashclash
3773 silver badges8 bronze badges
1