Ejemplo n.º 1
0
function handleUpload()
{
    $uploaddir = 'uploads/';
    $maxFileSize = 100 * 1024 * 1024;
    if (isset($_GET['qqfile'])) {
        $file = new UploadFileXhr();
    } elseif (isset($_FILES['qqfile'])) {
        $file = new UploadFileForm();
    } else {
        return array(success => false);
    }
    $size = $file->getSize();
    if ($size == 0) {
        return array(success => false, error => "File is empty.");
    }
    if ($size > $maxFileSize) {
        return array(success => false, error => "File is too large.");
    }
    $pathinfo = pathinfo($file->getName());
    $filename = $pathinfo['filename'];
    $ext = $pathinfo['extension'];
    // if you limit file extensions on the client side,
    // you should check file extension here too
    while (file_exists($uploaddir . $filename . '.' . $ext)) {
        $filename .= rand(10, 99);
    }
    $file->save($uploaddir . $filename . '.' . $ext);
    return array(success => true);
}
Ejemplo n.º 2
0
function handleUpload()
{
    $uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/files/';
    $maxFileSize = 100 * 1024 * 1024;
    if (isset($_GET['qqfile'])) {
        $file = new UploadFileXhr();
    } elseif (isset($_FILES['qqfile'])) {
        $file = new UploadFileForm();
    } else {
        return array(success => false);
    }
    $size = $file->getSize();
    if ($size == 0) {
        return array(success => false, error => "File is empty.");
    }
    if ($size > $maxFileSize) {
        return array(success => false, error => "File is too large.");
    }
    $pathinfo = pathinfo($file->getName());
    $filename = $pathinfo['filename'];
    $ext = $pathinfo['extension'];
    $filename = $filename ? $filename : rand(10, 99);
    // if you limit file extensions on the client side,
    // you should check file extension here too
    while (file_exists($uploaddir . $filename . '.' . $ext)) {
        $filename .= rand(10, 99);
    }
    $file->save($uploaddir . $filename . '.' . $ext);
    $imtypes = array(IMG_PNG => 'png', IMG_GIF => 'gif', IMG_JPG => 'jpg', IMG_WBMP => 'wbmp');
    if (!$ext) {
        $gis = exif_imagetype($uploaddir . $filename . '.' . $ext);
        if (in_array($gis, $imtypes)) {
            $ext_new = $imtypes[$gis];
            rename($uploaddir . $filename . '.' . $ext, $uploaddir . $filename . '.' . $ext_new);
            $ext = $ext_new;
        }
    }
    return array(success => true, 'filename' => $filename . '.' . $ext);
}
Ejemplo n.º 3
0
 /**
  * Implementation of getUploadForm()
  */
 protected function getUploadForm($message = '', $sessionKey = '', $hideIgnoreWarning = false)
 {
     $form = new UploadFileForm($this->targetTitle);
     $form->setTitle($this->getTitle($this->targetTitle));
     # display any upload error
     $form->addPreText($message);
     return $form;
 }