I write a module for a new field where I need to get access with imagemagick identify (not convert!) to a not saved file.
More precisely, I upload a pdf file in a widget. In a validation function I want to identify the size of a pdf.
The file before saving is like the following:
stdClass Object
(
[uid] => 1
[status] => 0
[filename] => bla.pdf
[uri] => /tmp/phpDS79Xg
[filemime] => application/pdf
[filesize] => 70322
[source] => field_imgext_und_0
[destination] => public://bla.pdf
)
Because I want to handle the file with shell_exec ("identify -format "%[pdf:HiResBoundingBox]" bla.pdf") I need the location of the cached file.
In my drupal conf at admin/config/media/file-system the temporary directory is sites/default/files/tmp. But I don't think that this has something to do with my issue because validation is before saving!
Because I want to exceed the image module I can strongly orientate the processes from this. The image module uses
getimagesize(drupal_realpath($image->source))
When I debug drupal_realpath, which is:
function drupal_realpath($uri) {
// If this URI is a stream, pass it off to the appropriate stream wrapper.
// Otherwise, attempt PHP's realpath. This allows use of drupal_realpath even
// for unmanaged files outside of the stream wrapper interface.
if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) {
return $wrapper->realpath();
}
// Check that the URI has a value. There is a bug in PHP 5.2 on *BSD systems
// that makes realpath not return FALSE as expected when passing an empty
// variable.
// @todo Remove when Drupal drops support for PHP 5.2.
elseif (!empty($uri)) {
watchdog("realpath", print_r($uri));
return realpath($uri);
}
return FALSE;
}
(watchdog from me). The realpath results in 1. (Which perhaps means TRUE). So there is a realpath and no file_stream_wrapper???
Do I have to save the file before I can get the size of the pdf???
Any ideas are welcome!!!
Thx, maen