if file exists help needed.

Discussion in 'PHP' started by sittsait, Sep 18, 2008.

  1. #1
    Hi,
    with this code i access the database table and get the image name in it.
    (Tested if the img name is correct here: http://www.aerix.org/test.php).
    Then script defines a variable.
    
    $test1 = "http://www.aerix.org/infusions/flash_games_system/puzzle/".$data['File']."";
    
    Code (markup):
    If it finds the file (named in MySQL table), it echos the img.
    If it doesnt find it, it will change dir and FIND image there.
    Img has to be in one of these 2.

    Help me out please:
    
    <?php
    require_once "maincore.php";
    $result = dbquery("SELECT File, Date
    					FROM fusion_flashgames_log
    					ORDER BY Date 
    					DESC LIMIT 0,1
    				");
    if (dbrows($result) != 0) {
       $data = dbarray($result);
    
    openside("Uus Flashmäng");
    $test1 = "http://www.aerix.org/infusions/flash_games_system/puzzle/".$data['File']."";
    if (file_exists($test1)) {
    echo "<img src='http://www.aerix.org/infusions/flash_games_system/puzzle/".$data['File']."'>";
    } else {
    echo "<img src='http://www.aerix.org/infusions/flash_games_system/notinpuzzle/".$data['File']."'>";
    }
    closeside();
    }
    ?>
    
    Code (markup):
    PROBLEM: It never finds the file defined by variable test1 and displays the second echo: .../notinpuzzle/...
    Appreciate your time :)
     
    sittsait, Sep 18, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    you are using too much variables in test1

    try to remove them and use simple url

    test it and then make it more general

    I am sure this will help

    Regards

    Alex
     
    kmap, Sep 18, 2008 IP
  3. sittsait

    sittsait Guest

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It didt work, i used :eek:
    
    $test1 = "http://www.aerix.org/index.php";
    
    Code (markup):
    And i need the changing variable in this line.
    
    ".$data['File']."
    
    Code (markup):
    is vital.
    Ty for reply.
     
    sittsait, Sep 18, 2008 IP
  4. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #4
    for checking if a file exists on url use this

    $fUrl = "http://www.aerix.org/index.php";
    $ders = @get_headers($fUrl);
    if (preg_match("|200|", $ders[0])) {
    // file exists
    } else {
    // file doesn't exists
    }

    Regards

    Alex
     
    kmap, Sep 18, 2008 IP
  5. sittsait

    sittsait Guest

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Used this now and it didnt work:

    
    <?php
    require_once "maincore.php";
    $result = dbquery("SELECT File, Date
    					FROM fusion_flashgames_log
    					ORDER BY Date 
    					DESC LIMIT 0,1
    				");
    if (dbrows($result) != 0) {
       $data = dbarray($result);
    
    openside("Uus Flashmäng");
    $fUrl = "http://www.aerix.org/index.php";
    $ders = @get_headers($fUrl);
    if (preg_match("|200|", $ders[0])) {
    echo "<img src='http://www.aerix.org/infusions/flash_games_system/puzzle/".$data['File']."'>";
    } else {
    echo "<img src='http://www.aerix.org/infusions/flash_games_system/notinpuzzle/".$data['File']."'>";
    }
    closeside();
    }
    ?>
    
    Code (markup):
    Same result. No pic, no errors.
     
    sittsait, Sep 18, 2008 IP