Start New Discussion within our Web Development Community

hello everyone, i am having a problem about my php code which tells that it cannot open a stream from function file(), and says 404 not found, true, but i already have filtered it but the error really comes out, but when i enter a valid id number, it produces no errors(ofcourse). What help am I going to need in solving this problem? To make it more understandable, I will give an example of the error message. (I am using XAMPP, and I still haven't uploaded it to any webhosting sites, this php file is still on my desktop. Nevermind the database connection and data insertion, it will still work without it.

Warning: file( failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\xampp\htdocs\kevinyuwow\naix.php on line 24"

Thank you in advance,


    <title>Hello Everybody!</title>
    <body bgcolor="black">
    <font color="pink"><b>ENTER YOUR ID NUMBER:</b></font><br>
    <form name="hello" action="naix.php" method="post">
    <input type="text" name="idnumUIC"><br>
    <input type="submit" value="Enter!">



    $url = "";
    $id = $_POST["idnumUIC"].".jpg";
    $complete = $url.$id;

    echo "<br> <br><center><font color=red><b>OMG THIS MUST BE YOU?!?!?!?!?!?</b></font><br><br>";

   /* $con = mysql_connect("localhost", "root", "");
    mysql_select_db("test", $con);

    $x = 0;

    $query = "insert into idnum_tbl (idnum_order, real_deal)";

    $gt = $_POST["idnumUIC"];

    $query2 = "values ('$x++','$gt')";

    $com = $query.$query2;

    mysql_query($com, $con); */

    for($x = 1; $x <= 30; $x++)

    echo "<img src=$complete>";

    if($x % 10 == 0)
    echo "<br>";




    echo "<center><font color=white><b>File doesn't exist. Try harder =)</b></font></center>";





file checks whether an .jpg exists or not. since i don't know how to use file_exists.

yes, that's my school :). but if i use that kind of snippet. it says the file doesn't exist, when in fact, it does, but the error message of failing to open the stream

yes 232.jpg doesn't really exist. if i enter a valid id number, for example 0900527, it will display (if I am going to use file($complete) as my condition.)

EDIT: as long as the id number is valid, you can access it without having to log in. I also just noticed that is_file() & is_link() didn't work too.

But, if you need to enter an ID.. why are you entering 323 over 0900527??

I don't understand what it is you're trying to do!

Here, try this:


    function _checkFileExists($url)
        $headers = @get_headers($url);
        if($headers[0] == 'HTTP/1.1 404 Not Found') {
            return false;
            return true;



    $url = "";
    $id = "0900527.jpg";

    $res = $url . $id;

      echo 'It exists';
     echo 'Sorry, it does not exist';

It worked, brilliant, sir! I just wanted to make sure that someone won't mess up :)

Thank you very much! I am trying now to understand the function that you have given me sir phorce =)



$headers = @get_headers($url);

we will get the headers from the specific url, store it into an array..

Then we'll check to see what the first element and check the response.. If there isn't a response then we'll return false otherwise return true..

This question has already been answered. Start a new discussion instead.