Save image to local

Public

Help save image url to local

</> CopyGet raw version
php
  1. $response = drupal_http_request($url);
  2. if ($response->code == 200) {
  3. $info = pathinfo($url);
  4. $directory = file_default_scheme() . '://' . 'images/' . date('Y') . '/' . date('n') . '/' . date('j');
  5. file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
  6. $file = file_save_data($response->data, $directory . '/' . $info['basename'], FILE_EXISTS_REPLACE);
  7. }