HTTP not supported by is_readable(), so use headers to determine if file is readable

This commit is contained in:
Nathan Gray 2011-12-13 17:42:32 +00:00
parent 3c30791c5c
commit d629b6322e

View File

@ -295,11 +295,33 @@
stream_wrapper_register(vfs_stream_wrapper::SCHEME, 'vfs_stream_wrapper', STREAM_IS_URL); stream_wrapper_register(vfs_stream_wrapper::SCHEME, 'vfs_stream_wrapper', STREAM_IS_URL);
} }
if ($data['type'] == 'import' && ($scheme == egw_vfs::SCHEME && !egw_vfs::is_readable($data['target']) || if ($data['type'] == 'import' && ($scheme == egw_vfs::SCHEME && !egw_vfs::is_readable($data['target'])))
$scheme != egw_vfs::SCHEME && !is_readable($data['target'])))
{ {
return lang('%1 is not readable',$data['target']); return lang('%1 is not readable',$data['target']);
} }
elseif ($data['type'] == 'import' && in_array($scheme, array('http','https')))
{
// Not supported by is_readable, try headers...
$options = array();
stream_context_set_default(array('http'=>array(
'method' => 'HEAD',
'ignore_errors' => 1
)));
$headers = get_headers($data['target'],1);
// Reset...
stream_context_set_default(array('http'=>array(
'method' => 'GET',
'ignore_errors' => 0
)));
// Response code has an integer key, but redirects may add more responses
for($i = 0; $i < count($headers); $i++)
{
if(!$headers[$i]) break;
if(strpos($headers[$i],'200') !== false) return true;
}
return lang('%1 is not readable',$data['target']);
}
elseif ($data['type'] == 'export' && !self::is__writable($data['target'])) { elseif ($data['type'] == 'export' && !self::is__writable($data['target'])) {
return lang('%1 is not writable',$data['target']); return lang('%1 is not writable',$data['target']);
} }
@ -408,7 +430,7 @@
foreach($targets as $target) foreach($targets as $target)
{ {
if($resource = @fopen( $target, $data['type'] == 'import' ? 'r' : 'w' )) { if($resource = @fopen( $target, $data['type'] == 'import' ? 'rb' : 'wb' )) {
$result = $po->$type( $resource, $definition ); $result = $po->$type( $resource, $definition );
fclose($resource); fclose($resource);