I am using remote files in my migration script. I store them like this:
<?php
$request = drupal_http_request($uri);
if ($request->code == 200) {
$file = new stdClass();
$file->fid = NULL;
$file->uri = $uri;
$file->filename = drupal_basename($uri);
$file->filemime = file_get_mimetype($file->uri);
$file = file_save($file);
}
?>
But the migration fails for a lot of files. I get error messages like this:
filesize(): stat failed for http://localhost/test.jpg File /includes/file.inc, line 570
Am I doing something wrong or is this a bug?
Comments
Comment #0.0
luksakTypo
Comment #0.1
luksakSyntax highlighting
Comment #0.2
luksakDeleting code
Comment #0.3
luksaktypo
Comment #1
bunnicula commentedDid you ever figure this out? I'm getting the same error.
Comment #2
luksakNo, I don't think so...
Comment #3
bunnicula commentedI tried using the same syntax as was used in the form_submit and this seems to work. The error still occurs but the file object is created anyway.
Comment #4
duaelfrI can confirm this issue.
file_save()always callsfilesize()that only works on local files.That module might rewrite the file_save function to bypass the filesize call or write its own as shown here.
Comment #5
twistor commented@Lukas von Blarer, yes you're doing something wrong :). filesize() works fine on stream wrappers. The only time this would fail is if the URL of the file isn't available.
For instance, http://localhost/test.jpg is probably not a valid, downloadable file.