Exemple #1
0
<?php

require_once 'Uploader.php';
$file;
$result;
if (isset($_FILES['upfile'])) {
    $uploader = new Uploader();
    $uploader->setTmpDir(__DIR__ . '/tmp');
    $uploader->setWriteDir(__DIR__ . '/file');
    $uploader->setMinSize('10');
    $uploader->setMaxSize('1000000');
    $file = $uploader->prepare('upfile');
    $uploader->execute();
    //$uploader->setNewName(mt_rand(10,200));
    $result = $uploader->commit();
}
?>


<!DOCTYPE html>
<html lang="ja">
<head>
	<title>ファイルアップロードサンプル</title>
	<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
</head>
<body>
<section class="jumbotron">
	<h2>ファイルアップロード - サンプル</h2>

	<article>
		<p>このファイルアップロードライブラリーではファイルをアップロード時に、最初に一時領域に格納し内容の確認後名前を付けてファイルを最終保存場所にアプロード(コミット)する事ができます。</p>
Exemple #2
0
 public function upload()
 {
     require_once dirname(ROOT) . DS . 'includes' . DS . 'upload.php';
     $data = array();
     $data['status'] = 0;
     if (!empty($_FILES['myfile'])) {
         $folder = $_GET['folder'];
         $root = dirname(ROOT) . DS . $folder;
         $root = str_replace('/', DS, $root);
         $root = str_replace(DS . DS, DS, $root) . DS;
         $uploader = new Uploader();
         $uploader->setDir($root);
         $uploader->setExtensions(array('jpg', 'jpeg', 'png', 'gif', 'svg', 'pdf', 'doc', 'txt', 'docx'));
         $uploader->setMaxSize(10);
         $uploader->sameName(false);
         if ($uploader->uploadFile('myfile')) {
             $data['status'] = 1;
             $image = $uploader->getUploadName();
             $src = $folder . '/' . $image;
             $data['file'] = array('title' => $image, 'url' => $src, 'file_name' => $image, 'thumb' => $src, 'file_type' => 'image');
         } else {
             $data['status'] = 0;
             $data['msg'] = $uploader->getMessage();
         }
         echo json_encode($data);
         exit;
     }
 }
Exemple #3
0
    $type = '';
}
require_once ROOT . DS . 'includes' . DS . 'functions.php';
$dg = new dg();
$lang = $dg->lang();
switch ($type) {
    case 'upload':
        require_once ROOT . DS . 'includes' . DS . 'upload.php';
        $data = array();
        $data['status'] = 0;
        if (!empty($_FILES['myfile'])) {
            $root = $dg->folder();
            $uploader = new Uploader();
            $uploader->setDir(ROOT . DS . $root);
            $uploader->setExtensions(array('jpg', 'jpeg', 'png', 'gif'));
            $uploader->setMaxSize(10);
            $uploader->sameName(false);
            if ($uploader->uploadFile('myfile')) {
                $data['status'] = 1;
                $image = $uploader->getUploadName();
                $data['src'] = $root . '/' . $image;
                $data['src'] = str_replace(DS, '/', $data['src']);
                $data['item'] = array('title' => $image, 'url' => $data['src'], 'file_name' => $image, 'thumb' => $data['src'], 'file_type' => 'image');
            } else {
                $data['status'] = 0;
                $data['msg'] = $uploader->getMessage();
                //get upload error message
            }
        }
        echo json_encode($data);
        exit;
 public function save()
 {
     $dgClass = new dg();
     if (!empty($_POST)) {
         $art = $_POST['art'];
         if (isset($_FILES["file"]["name"]) && $_FILES["file"]["name"] != '') {
             // create folder
             $root = dirname(ROOT) . DS . 'uploaded' . DS . 'cliparts' . DS . $art['cate_id'];
             if (!file_exists($root)) {
                 mkdir($root, 0755, TRUE);
             }
             $upload_path = $root . DS . 'print' . DS;
             if (!is_dir($upload_path)) {
                 mkdir($upload_path, 0755, TRUE);
             }
             // upload file
             require_once dirname(ROOT) . DS . 'includes' . DS . 'upload.php';
             $uploader = new Uploader();
             $uploader->setDir($upload_path);
             $uploader->setExtensions(array('jpg', 'jpeg', 'png', 'gif', 'svg'));
             $uploader->setMaxSize(10);
             $uploader->sameName(false);
             if ($uploader->uploadFile('file')) {
                 $image = $uploader->getUploadName();
                 $extension = $uploader->getExtension($image);
                 $extension = strtolower($extension);
                 $url = site_url('uploaded/cliparts/');
                 $url = str_replace('/admin/', '/', $url);
                 $art['file_type'] = $extension;
                 $art['file_name'] = $image;
                 $art['path'] = $url;
                 $art['url'] = $url . $art['cate_id'] . '/';
                 // create folder thumb
                 $thumbs = $root . DS . 'thumbs';
                 if (!is_dir($thumbs)) {
                     mkdir($thumbs, 0755, TRUE);
                 }
                 $medium = $root . DS . 'medium';
                 if (!is_dir($medium)) {
                     mkdir($medium, 0755, TRUE);
                 }
                 if ($extension == 'svg') {
                     $art['change_color'] = 1;
                     $art['thumb'] = 'print/' . $image;
                     $art['medium'] = 'print/' . $image;
                 } else {
                     require_once ROOT . DS . 'includes' . DS . 'thumb.php';
                     $thumb = new thumb($upload_path . $image);
                     $thumb->resize(null, 100, 100, $thumbs . DS . md5($image) . '.' . $extension);
                     $thumb->resize(null, 300, 300, $medium . DS . md5($image . 'medium') . '.' . $extension);
                     $art['thumb'] = 'thumbs/' . md5($image) . '.' . $extension;
                     $art['medium'] = '/medium/' . md5($image . 'medium') . '.' . $extension;
                     $art['change_color'] = 0;
                 }
             } else {
                 echo $uploader->getMessage();
             }
         }
         $art['price'] = (double) $art['price'];
         $file = dirname(ROOT) . DS . 'data' . DS . 'arts.json';
         // check file
         if (!file_exists($file)) {
             $dgClass->redirect('index.php/clipart');
             return;
         }
         $data = file_get_contents($file);
         $arts = json_decode($data);
         $is_new = true;
         $conent = array();
         if (isset($_POST['id']) && $_POST['id'] > 0) {
             $id = $_POST['id'];
             // update clipart
             if (isset($arts->arts) && count($arts->arts) > 0) {
                 foreach ($arts->arts as $row) {
                     if ($row->clipart_id == $id) {
                         $art['clipart_id'] = $id;
                         $conent[] = $art;
                         $is_new = false;
                     } else {
                         $conent[] = $row;
                     }
                 }
             }
         }
         if ($is_new === true) {
             $index = 0;
             foreach ($arts->arts as $row) {
                 if ($row->clipart_id > $index) {
                     $index = $row->clipart_id;
                 }
                 $conent[] = $row;
             }
             $art['clipart_id'] = $index + 1;
             $conent[] = $art;
             $arts->count = $arts->count + 1;
         }
         $arts->arts = $conent;
         $dgClass->WriteFile($file, json_encode($arts));
         $dgClass->redirect('index.php/clipart');
     } else {
         $dgClass->redirect('index.php/clipart');
     }
 }
    $model->iconUpdate($input, array('id' => $icon->id));
    $response->json($response);
} elseif ($route->match('iconimgupload', null)) {
    // Prepare and sanitize post input
    $api->setInputs($_POST);
    $icon = $model->iconFind(array('id' => $api->getInputVal('id'), 'user_id' => $user->id));
    if (!$icon) {
        $response->status = 404;
        $response->message = 'Not found';
        $response->json($response);
    }
    $uploader = new Uploader();
    $uploader->setDir('storage/icons/');
    $uploader->setExtensions(array('png', 'jpg', 'gif'));
    //allowed extensions list//
    $uploader->setMaxSize(0.2);
    $uploader->setCustomName($icon->name . '-' . $api->getInputVal('id') . '-' . time());
    if (!$uploader->uploadFile('file')) {
        $response->status = 500;
        $response->message = $uploader->getMessage();
        $response->json($response);
    }
    $model->iconUpdate(array('icon' => $uploader->getUploadName(), 'updated_at' => date("Y-m-d H:i:s")), array('id' => $icon->id));
    $path = 'storage/icons/' . $api->getInputVal('current');
    if (is_file($path)) {
        unlink($path);
    }
    $response->data = array('icon' => $uploader->getUploadName());
    $response->json($response);
} elseif ($route->match('userread', null)) {
    // Prepare and sanitize post input
Exemple #6
0
<?php

/**
 * Created by PhpStorm.
 * User: Cranky4
 * Date: 13.10.2015
 * Time: 18:04
 */
//стартуем сессию, если ее еще нет
session_start();
include_once "class/Uploader.php";
$uploader = new Uploader();
if ($_FILES && array_key_exists("pic", $_FILES)) {
    $uploader->setMaxSize(2 * 1024 * 1024);
    if ($pathInfo = $uploader->upload($_FILES['pic'])) {
        //сохраняем имя файла в сессию юзера
        $_SESSION['files'][] = $pathInfo['name'];
        //редирект на картинку
        header("Location: /task1/pic.php?path=/uploads/" . $pathInfo['name']);
    } else {
        //вывод ошибок
        print_r($uploader->getErrors());
    }
}
?>

<form method="POST" enctype="multipart/form-data">
    <input type="file" name="pic" required> <input type="submit" value="upload">
</form>

<ul>