Jump to content
Larry Ullman's Book Forums

Failed To Open Stream


Recommended Posts

hi im a java/ newbie php developer. I recently bought your book and it has great content, but I an failed to open stream error.

 

I have removed the path/to/dir with the correct value which is '/C:/xampp/htdocs/' and im still getting an error could there be something wrong with my path variable??

 

Link to comment
Share on other sites

An error occurred in script 'C:\xampp\htdocs\index.php' on line 7:
require(/C:/xampp/htdocs/mysql.inc.php): failed to open stream: Invalid argument
Array

(

[0] => Array

(

[file] => C:\xampp\htdocs\index.php

[line] => 7

[function] => my_error_handler

[args] => Array

(

[0] => 2

[1] => require(/C:/xampp/htdocs/mysql.inc.php): failed to open stream: Invalid argument

[2] => C:\xampp\htdocs\index.php

[3] => 7

[4] => Array

Link to comment
Share on other sites

 

the error is occuring in this code

 

// Are we live?

$live = false;

 

// Errors are emailed here:

$contact_email = '######@gmail.com';

 

// ************ SETTINGS ************ //

// ********************************** //

 

// ********************************** //

// ************ CONSTANTS *********** //

 

// Determine location of files and the URL of the site:

define('BASE_URI','/C:/xampp/htdocs/');

 

define('BASE_URL', 'http://localhost:8080/');

 

define('MYSQL', BASE_URI. 'mysql.inc.php');

 

// ************ CONSTANTS *********** //

// ********************************** //

 

// ********************************* //

// ************ SESSIONS *********** //

 

// Start the session:

session_start();

 

// ************ SESSIONS *********** //

// ********************************* //

 

// ****************************************** //

// ************ ERROR MANAGEMENT ************ //

 

// Function for handling errors.

// Takes five arguments: error number, error message (string), name of the file where the error occurred (string) 

// line number where the error occurred, and the variables that existed at the time (array).

// Returns true.

function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {

 

// Need these two vars:

global $live, $contact_email;

 

// Build the error message:

$message = "An error occurred in script '$e_file' on line $e_line:\n$e_message\n";

 

// Add the backtrace:

$message .= "<pre>" .print_r(debug_backtrace(), 1) . "</pre>\n";

 

// Or just append $e_vars to the message:

// $message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n";

 

if (!$live) { // Show the error in the browser.

 

echo '<div class="error">' . nl2br($message) . '</div>';

 

} else { // Development (print the error).

 

// Send the error in an email:

error_log ($message, 1, $contact_email, 'From:admin@example.com');

 

// Only print an error message in the browser, if the error isn't a notice:

if ($e_number != E_NOTICE) {

echo '<div class="error">A system error occurred. We apologize for the inconvenience.</div>';

}

 

} // End of $live IF-ELSE.

 

return true; // So that PHP doesn't try to handle the error, too.

 

} // End of my_error_handler() definition.

 

// Use my error handler:

set_error_handler ('my_error_handler');

 

Link to comment
Share on other sites

  my code now looks like this     and it pays to know
An error occurred in script 'C:\xampp\htdocs\index.php' on line 7:
require(/C:xampp/htdocs/mysql.inc.php): failed to open stream: Invalid argument
Array(    [0] => Array        (            [file] => C:\xampp\htdocs\index.php            [line] => 7            [function] => my_error_handler            [args] => Array                (                    [0] => 2                    [1] => require(/C:xampp/htdocs/mysql.inc.php): failed to open stream: Invalid argument                    [2] => C:\xampp\htdocs\index.php                    [3] => 7                    [4] => Array                        (                            [_GET] => Array                                (                                )                            [_POST] => Array                                (                                )                            [_COOKIE] => Array                                (                                    [sbOverlayID] => 51111639                                )                            [_FILES] => Array
Link to comment
Share on other sites

  • 2 weeks later...

?? in my require statement the slash is "behind" C because in the books it says our path should look like => '/path/to/web/folder/'

in which case my path is 'C:/Xampp/htdocs/'

 

in my script statement yes the slash "\"will be in front of C because its the physical file of my computer

Link to comment
Share on other sites

The error message suggests that your require path starts with a /: 

 

An error occurred in script 'C:\xampp\htdocs\index.php' on line 7:
require(/C:xampp/htdocs/mysql.inc.php): failed to open stream: Invalid argument
 
Also, on *nix systems, an initial / starts at the root directory. On Windows, the root directory is just C: (without a leading slash).
Link to comment
Share on other sites

yea im running on windows 64 bit. so i deleted the slash in front of C: now my base_uri looks like '/C:xampp/htdocs/'

and im still getting the error message

 

An error occurred in script 'C:\xampp\htdocs\html\index.php' on line 15:
require(/C:xampp/htdocs/mysql.inc.php): failed to open stream: Invalid argument

Array(    [0] => Array        (            [file] => C:\xampp\htdocs\html\index.php            [line] => 15            [function] => my_error_handler            [args] => Array                (                    [0] => 2                    [1] => require(/C:xampp/htdocs/mysql.inc.php): failed to open stream: Invalid argument                    [2] => C:\xampp\htdocs\html\index.php                    [3] => 15                    [4] => Array

if i use mu base uri 'C:xampp/htdocs/' "without the slash behind it" i get an exceed execution time error

 

 

 

ive tried multiple uri combinations could there be something more than a simple uri error maybe a path environment variable issue?

Link to comment
Share on other sites

 Share

×
×
  • Create New...