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(http://www3.uic.edu.ph/images/100x102/1242343.jpg): 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,

Kevin.

    <html>
    <title>Hello Everybody!</title>
    <body bgcolor="black">
    <center>
    <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!">
    </form>

    </center>
    <?php



    if(isset($_POST["idnumUIC"]))
    {

    $url = "http://www3.uic.edu.ph/images/100x102/";
    $id = $_POST["idnumUIC"].".jpg";
    $complete = $url.$id;


    if(file($complete))
    {
    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>";
    }

    }

    mysql_close($con);

    }

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

    }



    ?>

    </body>


    </html>

http://www3.uic.edu.ph/images/100x102/1242343.jpg

Doesn't exist, or, you do not have permissions to access it.

Please can you vardump / echo $complete...

Also, what does "file" do? :S

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

if(file_exists($complete))
{
    // true
}else{

  // false
}

EDIT: It doesn't look like "http://www3.uic.edu.ph/images/100x102/232.jpg" exists, or, you do not have permission.. Is this your School/College by any chance, and works for you when you sign into the service?

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:

<?php

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

        }

    }

    $url = "http://www3.uic.edu.ph/images/100x102/";
    $id = "0900527.jpg";

    $res = $url . $id;

    if(_checkFileExists($res))
      echo 'It exists';
    else
     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 =)

Hey,

so

$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..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.