本文整理汇总了PHP中fileupload::common_checks方法的典型用法代码示例。如果您正苦于以下问题:PHP fileupload::common_checks方法的具体用法?PHP fileupload::common_checks怎么用?PHP fileupload::common_checks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fileupload
的用法示例。
在下文中一共展示了fileupload::common_checks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_common_checks_valid_file
public function test_common_checks_valid_file()
{
$upload = new fileupload($this->filesystem, '', array('jpg'), 1000);
$file = $this->gen_valid_filespec();
$upload->common_checks($file);
$this->assertEquals(0, sizeof($file->error));
}
示例2: remote_upload
//.........这里部分代码省略.........
$phpbb_root_path = objects::$phpbb_root_path;
$upload_ary = array();
$upload_ary['local_mode'] = true;
$upload_from_phpbb = preg_match(objects::$phpbb_link_template, $upload_url, $match_phpbb);
if (!preg_match('#^(https?://).*?\\.(' . implode('|', $files->allowed_extensions) . ')$#i', $upload_url, $match) && !$upload_from_phpbb) {
$file = new \fileerror($user->lang[$files->error_prefix . 'URL_INVALID']);
return $file;
}
if (empty($match[2]) && empty($match_phpbb[2])) {
$file = new \fileerror($user->lang[$files->error_prefix . 'URL_INVALID']);
return $file;
}
$url = parse_url($upload_url);
$host = $url['host'];
$path = $url['path'];
$port = !empty($url['port']) ? (int) $url['port'] : 80;
$upload_ary['type'] = 'application/octet-stream';
$url['path'] = explode('.', $url['path']);
$ext = array_pop($url['path']);
$url['path'] = implode('', $url['path']);
$upload_ary['name'] = utf8_basename($url['path']) . ($ext ? '.' . $ext : '');
$filename = $url['path'];
$filesize = 0;
$remote_max_filesize = $files->max_filesize;
if (!$remote_max_filesize) {
$max_filesize = @ini_get('upload_max_filesize');
if (!empty($max_filesize)) {
$unit = strtolower(substr($max_filesize, -1, 1));
$remote_max_filesize = (int) $max_filesize;
switch ($unit) {
case 'g':
$remote_max_filesize *= 1024;
// no break
// no break
case 'm':
$remote_max_filesize *= 1024;
// no break
// no break
case 'k':
$remote_max_filesize *= 1024;
// no break
}
}
}
$errno = 0;
$errstr = '';
if (!($fsock = @fopen($upload_url, "r"))) {
$file = new \fileerror($user->lang[$files->error_prefix . 'NOT_UPLOADED']);
return $file;
}
// Make sure $path not beginning with /
if (strpos($path, '/') === 0) {
$path = substr($path, 1);
}
$get_info = false;
$data = '';
$length = false;
$timer_stop = time() + $files->upload_timeout;
while (!@feof($fsock)) {
if ($length) {
// Don't attempt to read past end of file if server indicated length
$block = @fread($fsock, min($length - $filesize, 1024));
} else {
$block = @fread($fsock, 1024);
}
$filesize += strlen($block);
if ($remote_max_filesize && $filesize > $remote_max_filesize) {
$max_filesize = get_formatted_filesize($remote_max_filesize, false);
$file = new \fileerror(sprintf($user->lang[$files->error_prefix . 'WRONG_FILESIZE'], $max_filesize['value'], $max_filesize['unit']));
return $file;
}
$data .= $block;
// Cancel upload if we exceed timeout
if (time() >= $timer_stop) {
$file = new \fileerror($user->lang[$files->error_prefix . 'REMOTE_UPLOAD_TIMEOUT']);
return $file;
}
}
@fclose($fsock);
if (empty($data)) {
$file = new \fileerror($user->lang[$files->error_prefix . 'EMPTY_REMOTE_DATA']);
return $file;
}
$tmp_path = @is_writable('/tmp/') ? '/tmp/' : $phpbb_root_path . 'cache/';
$filename = tempnam($tmp_path, unique_id() . '-');
if (!($fp = @fopen($filename, 'wb'))) {
$file = new \fileerror($user->lang[$files->error_prefix . 'NOT_UPLOADED']);
return $file;
}
$upload_ary['size'] = fwrite($fp, $data);
fclose($fp);
unset($data);
$upload_ary['tmp_name'] = $filename;
$file = new \filespec($upload_ary, $files, $mimetype_guesser);
if ($upload_from_phpbb) {
$file->extension = 'zip';
}
$files->common_checks($file);
return $file;
}