Jump to content

get image according to date function.


mp04

Recommended Posts

Hey,

I have a script that was custom made for me that, grabs a image from another site (my own other site) the script is:

 

 
<?


    $filename="URL To other site";
    $indirectory="Directory where the image is";
    $destinationpath="Path to where it should save it.";



    $contents = file_get_contents($filename);
    $url=dirname($filename);
    $keywords=0;
    $keywords1=0;

    $keywords = strpos($contents,"src");
    while ($keywords>0)
    {
        $filename=retbetween1($contents,"src=\"","\"",$keywords1);

        if (substr($filename,-4)==".jpg")
        {
            if (strpos($filename,$indirectory)>0)
            {
                echo "Writing file ";
                if (substr($filename,0,7)=="http://")
                {
                    $bname=basename($filename);
                    $contents1 = file_get_contents($filename);
                    echo $filename." to ";
                    file_put_contents($destinationpath,$contents1);
                    echo "$destinationpath. Success";
                }
                else
                {
                    $bname=basename($filename);
                    $contents1 = file_get_contents($url."/".$filename);
                    echo $url."/".$filename." to ";
                    file_put_contents($destinationpath,$contents1);
                    echo "$destinationpath. Success";
                }
            }
        }
    }


function retbetween($mainstring,$search,$search1,$cnt)
{
    global $sttable;
    global $keywords;
    global $keywords1;

    $keywords = strpos($mainstring,$search,$cnt);

    $keywords1 = strpos($mainstring,$search1,$keywords+strlen($search));
    $sl=strlen($search);
    $s2=strlen($search1);
    $strw=substr($mainstring,$keywords,($keywords1+$s2)-($keywords));
    $sttable=$keywords1+$s2;
    return $strw;

}
function retbetween1($mainstring,$search,$search1,$cnt)
{
    global $sttable;
    global $keywords;
    global $keywords1;
    $keywords = strpos($mainstring,$search,$cnt);
    if ($keywords>0)
    {
        $keywords1 = strpos($mainstring,$search1,$keywords+strlen($search));
        $sl=strlen($search);
        $s2=strlen($search1);
        $strw=substr($mainstring,$keywords+strlen($search),($keywords1)-($keywords+strlen($search)));
        $sttable=$keywords1+$s2;
        return $strw;
    }
    else
        return "";

}

?>
</form>
</body>
</html>

 

 

 

Now this has worked perfectly so far, since site would only show one image a day, and server would go there, and pick up that one image from that one folder.

 

Now, We have made some changes to the daily image feature on the web, where the user can go back a few days or months etc, BUT on the site it self it shows 5 pictures from the last five days now. SO now the server is confused as far as which ONE image it should grab. causeing the script to now stall.

 

So basically what we did I talked with the admin to the page and he said what he can do is name each image with a date, so today image would be: 08-07-09.jpg.

 

what I want to do, is maybe a addition to that script above so it can get the date from the server, and match it with the image and THEN transfer it.

 

any ideas? Please remember I am a newbie to PHP and still learning, so please keep that in mind.

 

Thanks.

 

Link to comment
Share on other sites

You can get the filename of the image by exploding on the period (or you can so a substr since the date in the filename is a fixed length) and compare the first chunk against today's date, which would be date("m-d-Y") in your case. If they match then display. www.php.net is a good resource, look up "explode" and "date".

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.