0

so iam trying to download images by this code i successfully download the images but they without any data and corrupted

like the images have 0 bytes

function get_chapter_images(){

include('simple_html_dom.php');

$url = 'http://localhost/wordpress/manga/manga-name-ain/chapter-4/';


 $html = file_get_html($url);

 $images_url = array();

foreach($html->find('.page-break img') as $e){

  $image_links =  $e->src;

array_push( $images_url, $image_links);

   }

   return $images_url;

}
$images_links = get_chapter_images();

    foreach( $images_links as $image ){

        $imag_fliter = str_replace( '?ssl=1', '', $image );

        $data = @file_get_contents( $image );

                $pathinfo = pathinfo( $image );

                    $file_name = $pathinfo['basename'];

                    @file_put_contents("manld/$file_name", $data );

    }
  • 1
    It's likely the image paths are invalid. But you suppress any error reporting by PHP, using the `@` character, so you'll never know. Why not `print_r()` the found `$images_url` and see what it contains? – KIKO Software Mar 09 '20 at 07:18
  • it containts array Array ( [0] => http://localhost/wordpress/wp-content/uploads/WP-manga/data/manga_5e62092804a6d/f6954e41130c0015b5b89a3021d55595/1.jpg – التقنية tech Mar 09 '20 at 07:24
  • when i remove @ i get those errors Warning: file_get_contents – التقنية tech Mar 09 '20 at 07:27
  • 1
    OK, so the beginning of the path is probably the problem. It should either have `http://` or `https://` to use the HTTP protocol (if that is allowed), or a proper OS path. The latter is the better option, of course, since you're using `localhost`. – KIKO Software Mar 09 '20 at 07:27
  • 1
    Just to remind you: A browser uses URL's, functions like `file_get_contents()` use OS filesystem paths. The latter can sometimes also use HTTP URLs. Your image links are neither. – KIKO Software Mar 09 '20 at 07:30
  • I tryed to put http befor url by but i get space between them http:// localhost/wordpress/wp-conte $url1 = str_replace( 'http://', '', $url ); $http = 'http://'; $urlo = $http . $url1; – التقنية tech Mar 09 '20 at 13:37
  • It's difficult to understand what your problem is. Why don't you ask a new question? State what string you start with, what you want to end up with, what you have tried to get there, and finally what's wrong. – KIKO Software Mar 09 '20 at 13:49

0 Answers0