Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
web1868

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??

 

Share this post


Link to post
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

Share this post


Link to post
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');

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

?? 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

Share this post


Link to post
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).

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...