I would love a way to "upload" from the web. If I want to load an image from some other web site, I first have to download it locally and then upload it through IMCE. It'd be great if we could just give IMCE a url and it would curl or wget the image itself.

CommentFileSizeAuthor
#5 urlupload-740248-3.patch6.8 KBNikit
#5 imce_url01.jpg46.36 KBNikit
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ALexeyAL1’s picture

+1
Very useful function, I hope probably it to realise.

ufku’s picture

Status: Active » Closed (won't fix)

Closing 6.x-1.x issues as this branch is no more supported.

AaronBauman’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue summary: View changes
Status: Closed (won't fix) » Active

This would still be a useful feature.

marcus7777’s picture

I'm working on this too:

This code gets all the images from a dropbox shared folder

Needs work and moving in to ops-list in IMCE. I love some help.

I'm looking for a good way/place to put it

function get_images_from_url_node_validate($node, $form, &$form_state) {
        if (isset($node->field_get_image_from['und'][0]['value'])) {
                $url =$node->field_get_image_from['und'][0]['value'] ;
                if (filter_var($url, FILTER_VALIDATE_URL)) {
                        if ($wrapper = file_stream_wrapper_get_instance_by_uri('public://')) {
                                $realpath = $wrapper->realpath();
                        }
                        if (isset($node->title_field['und'][0]['value'])) {
                          $structure=$realpath.'/'.$node->type.'/'.$node->title_field['und'][0]['value'].'/';
                          $path = $node->type.'/'.$node->title_field['und'][0]['value'].'/';
                        } else {
                          $structure=$realpath.'/'.$node->type.'/';
                          $path = $node->type.'/';
                        }
                        $html = file_get_contents($url);
                        //Create a new DOM document
                        $dom = new DOMDocument;

                        //Parse the HTML. The @ is used to suppress any parsing errors
                        //that will be thrown if the $html string isn't valid XHTML.
                        @$dom->loadHTML($html);

                        //Get all links. You could also use any other tag name here,
                        //like 'img' or 'table', to extract other tags.
                        $links = $dom->getElementsByTagName('a');
                        //Iterate over the extracted links and display their URLs
                        $jpgs = Array();
                        foreach ($links as $link){
                                //Extract "href" attribute.
                                //filter jpg and uniq
                                if (preg_match("/jpg/i", $link->getAttribute('href'))) {
                                        $jpgs [$link->getAttribute('href')] = $link->getAttribute('href');
                                }
                        }
                        $img = 0;
                        foreach ($jpgs as $jpg) {
                                //make folder

                                @mkdir($structure, 0766, true);
                                //copy file
                                //file_put_contents($structure . ++$img . ".jpg", file_get_contents($jpg));
                                $ch = curl_init($jpg .'?dl=1');
                                $fp = fopen($structure . ++$img . "-bf.jpg", 'wb');
                                curl_setopt($ch, CURLOPT_FILE, $fp);
                                curl_setopt($ch, CURLOPT_HEADER, 0);
                                curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");
                                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                                curl_exec($ch);
                                curl_close($ch);
                                fclose($fp);

                        }
                        drupal_set_message('Uploaded '.$img .' images to '. $path );
                }
        }
}
Nikit’s picture

Status: Active » Needs review
Issue tags: +imce, +url, +upload
FileSize
46.36 KB
6.8 KB

I have create patch for 7.x.-1.x. that allow upload by URL link.

Screenshot of IMCE URL usage

thalles’s picture

Hi @ufku! Can this cause security problems?

thalles’s picture

Category: Feature request » Support request

This can cause some issues, so, I think better not, see: https://www.wordfence.com/learn/how-to-prevent-file-upload-vulnerabilities/

thalles’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.