I want to get the contents of my install.sql file that sits one directory up but when I use file_get_contents("../install.sql") it returns false.
How can I fix it?
I have also tried to use fopen and fread.
<?php // Get the install SQL Files if (@$install_sql = file_get_contents("../install.sql")){ // Prepare the statement to install $install_stmt = $conn_test->prepare($install_sql); // Execute the install $install_stmt->execute(); } else { // This is where the code ends up } ?> Code shortened
Full code available here
For people suggesting to remove '@' to show errors:
Warning: file_get_contents(../install.sql): failed to open stream: No such file or directory in /Users/yigitkerem/Code/SkyfallenSecureForms/Configuration/install.php on line 55 For me it wasn't making any more sense, that was why I didn't include it, but here we go in case there is something that I don't know.
@, and look at your error log for warnings/errors.@) obscures problems with your code and makes debugging issues like this a whole lot more complicated. That's a tool of last resort and should only be used in exceptional circumstances. You should display an error message for the user, log a problem, initiate some kind of retry, or all of these things in conjunction.var_dump(is_file('../install.sql'))and check if the path is correct. Also make sure the file isn't empty (since an empty string would be evaluated as false here.) But yes, as @Luuk said, start by remove the@since that suppresses useful error messages.