51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
|
<?php
|
||
|
|
||
|
class PostedFile extends LocalFile
|
||
|
{
|
||
|
var $shouldMove = true;
|
||
|
|
||
|
function __construct($name)
|
||
|
{
|
||
|
$this->name = $name;
|
||
|
if (!is_uploaded_file(@$_FILES[$this->name]['tmp_name']))
|
||
|
{
|
||
|
throw new Exception("No POSTed file with name $name");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static function newFromName($name)
|
||
|
{
|
||
|
if (is_uploaded_file(@$_FILES[$name]['tmp_name']))
|
||
|
{
|
||
|
return new self($name);
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
function __destruct()
|
||
|
{
|
||
|
$tmp_name = $_FILES[$this->name]['tmp_name'];
|
||
|
if (@is_uploaded_file($tmp_name))
|
||
|
{
|
||
|
// Unlink temporary upload
|
||
|
@unlink($tmp_name);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function getLocalPath()
|
||
|
{
|
||
|
return $_FILES[$this->name]['tmp_name'];
|
||
|
}
|
||
|
|
||
|
function getFileName()
|
||
|
{
|
||
|
if (isset($_FILES[$this->name]['name']))
|
||
|
{
|
||
|
$name = trim($_FILES[$this->name]['name']);
|
||
|
$name = preg_replace('#^.*[/\\\\]#is', '', $name);
|
||
|
return $name;
|
||
|
}
|
||
|
return '';
|
||
|
}
|
||
|
}
|