Search
 
SCRIPT & CODE EXAMPLE
 

PHP

image downlord

<?php

class ImageDownload
{
    /**
     * file directory path
     *
     * @return void
     */
    public $folder = 'images';

    /**
     * website link
     *
     * @return void
     */
    public $websitelink;

    /**
     * Create a new class instance.
     *
     * @return void
     */
    function __construct($websitelink)
    {        
        if (!file_exists($this->folder)) {
            mkdir($this->folder, 0777, true);
        }
        $this->websitelink = $websitelink;
    }

    /**
     * save file.
     *
     * @return void
     */
    public function getLinks()
    {
        $html = file_get_contents($this->websitelink);

        preg_match_all("{<imgs*(.*?)src=('.*?'|".*?"|[^s]+)(.*?)s*/?>}ims", $html, $image_urls, PREG_SET_ORDER);

        return $image_urls;
    }

    /**
     * save file.
     *
     * @return void
     */
    public function saveImage($images)
    {
        foreach ($images as $val) {
            $pos = strpos($val[2],"/");
            
            $link = substr($val[2],1,-1);
            
            if($pos == 1) {
                $site = parse_url($this->$websitelink);

                $image_url = $site['scheme'].'://'.$site['host'].$link;


            } else {
                $image_url = $link;
            }
            $image_name = pathinfo($image_url)['basename'];
            
            copy($image_url, $this->folder.'/'.$image_name);
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: how to write double values in phpmyadmin 
Php :: Comment désactiver la barre latérale Widgets sur des pages spécifiques WordPress 
Php :: laravel-filemanager 404 error 
Php :: detect mobile device laravel 
Php :: update request php-salesforce-rest-api 
Php :: generate random color php 
Php :: 0.02 eth to php 
Php :: get categories only assigned to post Wordpress 
Php :: php unit testAdd Answer 
Php :: strtolower cyrillic 
Php :: laravel helper functions 
Php :: php code for fetching data from database 
Php :: php pdo fetch from db 
Php :: convert string to int php 
Php :: wordpress change permalink on upload 
Php :: laravel seeder multiple column 
Php :: laravel validation alphanumeric with spaces 
Php :: how to make a timer in php 
Php :: pagination php 
Php :: change php version 
Java :: import java math 
Java :: setting up javafx in eclipse vm argument 
Java :: jcenter is at end of life 
Java :: java get mouse position on screen 
Java :: copy array in java 2d 
Java :: change visibility of textview andoird 
Java :: java random 6 digit number 
Java :: How to implement a Trie data structures in Java? 
Java :: sololearn java shapes coding project 
Java :: listview refresh android adapter 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =