sql - Require() php error when trying to include files -


hi i'm trying include functions in php script keep getting error i'm struggling figure out. i've gone through permissions , few other things no avail.

here's php - code within test few things , don't think not effecting 'require()' call, maybe wrong obviously.

#!/usr/bin/env php <?php require(__dir__ . "/../includes/config.php");  if ($argc !=2) {     print("please specify file path \n");     return -1; }  $file = $argv[1]; print($file);  if (!file_exists($file))     {         print("error: file " . $file . " doesn't exist\n");         //return -1;       }   if (is_writable($file))      {         $copy = 'copy1.txt';          $handle = file_get_contents($file);          file_put_contents($copy, $handle);      }   else      {         echo "the file $filename not writable \n";     } end;  $test = query("insert  `pset8`.`places` (         `id` ,         `country_code` ,         `postal_code` ,         `place_name` ,         `admin_name1` ,         `admin_code1` ,         `admin_name2` ,         `admin_code2` ,         `admin_name3` ,         `admin_code3` ,         `latitude` ,         `longitude` ,         `accuracy`         )         values (         '2',  '',  '',  '',  '',  '',  '',  '',  '',  '',  '',  '',  ''         )");  ?> 

and here error:

php warning:  require(../vendor/library50-php-5/cs50/cs50.php): failed open stream: no such file or directory in /home/ubuntu/workspace/pset8/includes/config.php on line 20 php stack trace: php   1. {main}() /home/ubuntu/workspace/pset8/bin/import:0 php   2. require() /home/ubuntu/workspace/pset8/bin/import:3  warning: require(../vendor/library50-php-5/cs50/cs50.php): failed open stream: no such file or directory in /home/ubuntu/workspace/pset8/includes/config.php on line 20  call stack:     0.0002     235656   1. {main}() /home/ubuntu/workspace/pset8/bin/import:0     0.0022     238328   2. require('/home/ubuntu/workspace/pset8/includes/config.php') /home/ubuntu/workspace/pset8/bin/import:3  php fatal error:  require(): failed opening required '../vendor/library50-php-5/cs50/cs50.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/ubuntu/workspace/pset8/includes/config.php on line 20 php stack trace: php   1. {main}() /home/ubuntu/workspace/pset8/bin/import:0 php   2. require() /home/ubuntu/workspace/pset8/bin/import:3  fatal error: require(): failed opening required '../vendor/library50-php-5/cs50/cs50.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/ubuntu/workspace/pset8/includes/config.php on line 20  call stack:     0.0002     235656   1. {main}() /home/ubuntu/workspace/pset8/bin/import:0     0.0022     238328   2. require('/home/ubuntu/workspace/pset8/includes/config.php') /home/ubuntu/workspace/pset8/bin/import:3 

thanks in advance!

this not permissions-issue, it's matter of including files correct paths. can read off errors, , stated in comments, includes/requires seems including wrong paths.

accodring documentation, __dir__ returns path of current file. example, config.php file return /home/ubuntu/workspace/pset8/includes.

when use /../ @ end when including (ex: include __dir."/../";), means go folder, ending on path /home/ubuntu/workspace/pset8. can multiple times (ex: include __dir."/../../"; end on /home/ubuntu/workspace).

so basically, you'll need know @ times, , include that. hard-code (so include "/home/ubuntu/workspace/pset8/includes/config.php";), suggest more dynamic approach (should end using different host, change few lines instead of many).

you define variable include from, like

define("basefolder", "/home/ubuntu/workspace/pset8"); require basefolder."/includes/config.php"; 

note need define basefolder each file, it's not global definition.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -