www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28

Thread: how to extract img src from an external list

  1. #16
    Join Date
    Apr 2005
    Posts
    46
    I just noticed that the image ordering is a bit different than they should be..
    Edit: ooops. Its the fault of the original website, not your script!
    Last edited by sallam; 09-24-2012 at 01:23 PM.

  2. #17
    Join Date
    Apr 2005
    Posts
    46
    Is there a way to protect the php file from being used from outside domains?. I want to protect my server resources..

  3. #18
    Join Date
    Mar 2009
    Posts
    452
    edit existing (in your www or public_html folder) or Create a new text file and save it as .htaccess with the following:
    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yourdomain/ [NC]
    RewriteRule images.(php)$ http://i.imgur.com/qX4w7.gif [L]

    replace yourdomain with your own domain and http://i.imgur.com/qX4w7.gif to whatever page you want to show to prevented requests.

  4. #19
    Join Date
    Apr 2005
    Posts
    46
    Worked very nicely. I tried it from another domain and it showed no images. Thank you SABI sooo much for your time and help.

    I want to ask you a different question. My 20 pages have parts with identical html code lines, is it possible to use one centralized file where I save those parts, then all the pages extract those parts from it? Sort of a template but only for specific parts of html not all the page content?.. because right now, every time I want to change a line of code, I have to do it repeatedly in each of the 20 pages..

  5. #20
    Join Date
    Mar 2009
    Posts
    452
    Yes you can do that in PHP using include() directive/function; for this you will need to convert those pages to PHP (or simly rename .html to .php) then you can import external file where ever you want to.

    .
    .
    .
    <body>

    .
    .
    .
    <?php include('common.html');?>
    .
    .
    .

    </body>
    .
    .
    .

    you can use html, js, css, txt, php etc...



    my nick is ZABI by the way

  6. #21
    Join Date
    Apr 2005
    Posts
    46
    Ooops.. sorry about that ZABI
    So if say there are 5 repeated lines from line 3 to line 7, then 2 repeated lines from line 10 to 11, should I create separate common.html files for each group of lines, and type the include command twice in place of the 2 sets of lines? or use one common.html file for all the parts? and if so, how do I guide the pages to each part in the common file?
    An example please?

  7. #22
    Join Date
    Mar 2009
    Posts
    452
    you can have as many external files as you wish, you can also include a php file that has included another and so on.

    for example you have a.php containing 5 lines for all your files.
    b.php contains 3 lines to be used in 2 files,


    so you can use <?php include('b.php');?>

    where as b.php may contain

    <?php include('a.php');?>
    some other content
    .
    .
    .
    .
    .

  8. #23
    Join Date
    Apr 2005
    Posts
    46
    Got it. You've been very helpful ZABI.
    Thanks very much for your generosity and kindness.

  9. #24
    Join Date
    Mar 2009
    Posts
    452
    I love to help always Thank you too.

  10. #25
    Join Date
    Apr 2005
    Posts
    46
    Quote Originally Posted by ZABI View Post
    now you just have to use this php file in place of your external js file
    no need for updating or writing to files or any thing else, it will automatically generate array when accessed

    PHP Code:
    <?php
    $source
    ='http://www.spinneys.com/sites/Egypt/News.aspx?pageid=54';
    @
    fopen($source'r') or die('Error accessing URL');

    $find=array('Thumb','Photo_','../');
    $replace=array('Photo','','http://www.spinneys.com/sites/');

    $ddoc = new DOMDocument();
    @
    $ddoc->loadHTMLFile($source);
    $tags $ddoc->getElementsByTagName('img');

    echo 
    "var images=new Array();\r\n";
    $i=1;

    foreach (
    $tags as $tag) {
        
    $src $tag->getAttribute('src');        
        if (@
    strpos($src,'ContentPhotos')!==false){
            echo 
    "images[$i]='".str_replace($find,$replace,$src)."';\r\n";
            
    $i++;
        }
    }
    ?>
    ZABI, please help me. The site has changed the location of the images. Now the images' URLs are like this:
    Code:
    spinneys.com/Library/Images/Spinneys%20flyer0-01.jpg
    and sometimes like this..
    Code:
    spinneys.com/Library/Images/Spinneys%20flyer01.jpg
    What changes should I make to your script above please?
    Last edited by sallam; 12-20-2012 at 06:21 PM.

  11. #26
    Join Date
    Mar 2009
    Posts
    452
    Well i think it should still work as expected.

    what is the problem you are facing ?

  12. #27
    Join Date
    Apr 2005
    Posts
    46
    The script is no longer pulling any images.
    The script was pulling images from their urls listed in a webpage:
    spinneys.com/sites/Egypt/News.aspx?pageid=54

    But now there is no webpage, and I have to pull the images from the directory where they are saved:
    spinneys.com/Library/Images/
    Last edited by sallam; 01-07-2013 at 05:43 PM.

  13. #28
    Join Date
    Apr 2005
    Posts
    46
    I'm having a similar problem. I need to embed images in my webpage, extracted from another website directory. The images change each week. I'm currently using code like this:
    Code:
    <p style="text-align: center;">
    <img id="img" src="http://www.panda.com.sa/promotions/Zone3/HyperPanda/files/assets/flash/pages/page0001.jpg" width="100%" /> </p>
    <p style="text-align: center;">
    <img id="img" src="http://www.panda.com.sa/promotions/Zone3/HyperPanda/files/assets/flash/pages/page0002.jpg" width="100%" /> </p>
    <p style="text-align: center;">
    <img id="img" src="http://www.panda.com.sa/promotions/Zone3/HyperPanda/files/assets/flash/pages/page0003.jpg" width="100%" /> </p>
    all the way up to images: 0064.jpg
    The problem is there are not always 64 images in that directory. Sometimes they're 48 or 32.
    So I need the code to make an arrey depending on the number of image files in that directory, to avoid having empty frames in my webpage if I repeat the above html lines 64 times.

    Many thanks for any help given.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles