dongshi2588 2015-08-20 14:58
浏览 31

修改http://codecanyon.net/中的“Multiple File Uploader”以选择数据库目的地

So I know buying code is cheating but I'm under some time restraints at the moment.
The code easily allows the user to upload files to a directory(db).
It works perfectly other than I need to have a section of multiple database destinations

<?php



   include('config.php');
   include('image_control_class.php');

   // 5 minutes execution time
   @set_time_limit(5 * 60);
   $cleanupTargetDir = true; 
   $maxFileAge = 5 * 3600; 

   if (!file_exists(UPLOAD_PATH)) {
       @mkdir(UPLOAD_PATH);
       }
   if (isset($_REQUEST["name"])) {
       $fileName = $_REQUEST["name"];
       } elseif (!empty($_FILES)) {
       $fileName = $_FILES["file"]["name"];
       } else {
       $fileName = uniqid("file_");
       }
   if(FILE_RENAME==true){
       $fileExt = substr($fileName, strrpos($fileName, '.'));
       $mianext=substr($fileExt,1);
       $fileName = substr(rand(0,999999999999999),2,6).substr(time(),6).'.'.$mianext;
       }

$filePath = UPLOAD_PATH . DIRECTORY_SEPARATOR . $fileName;
$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
$chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;

// Remove old temp files    
    if ($cleanupTargetDir) {
 if (!is_dir(UPLOAD_PATH) || !$dir = opendir(UPLOAD_PATH)) {
    die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
    }

     while (($file = readdir($dir)) !== false) {
     $tmpfilePath = UPLOAD_PATH . DIRECTORY_SEPARATOR . $file;

      // If temp file is current file proceed to the next
     if ($tmpfilePath == "{$filePath}.part") {
        continue;
       }
            if (preg_match('/\.part$/', $file) && (filemtime($tmpfilePath) < time() - $maxFileAge)) {
        @unlink($tmpfilePath);
    }
    }
   closedir($dir);
    }   

       if (!$out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb")) {
       die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
  }

       if (!empty($_FILES)) {
        if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]   ["tmp_name"])) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
     }

    // Read binary input stream and append it to temp file
    if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
     }
 } else {   
    if (!$in = @fopen("php://input", "rb")) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to     open input stream."}, "id" : "id"}');
    }
}

while ($buff = fread($in, 4096)) {
    fwrite($out, $buff);
}

@fclose($out);
@fclose($in);

if (!$chunks || $chunk == $chunks - 1) {
    rename("{$filePath}.part", $filePath);

    $hezeimage = new Hezeresizer(UPLOAD_PATH .'/'.$fileName);
    $hezeimage->ResizeImageTo(THUMB_IMAGE_WIDTH, THUMB_IMAGE_WIDTH, 'crop');
    $hezeimage->SaveImageTo(UPLOAD_PATH_THUMB.$fileName,90);
    $hezeimage->ResizeImageTo(BIG_IMAGE_WIDTH, BIG_IMAGE_WIDTH, 'resize');
    $hezeimage->SaveImageTo(UPLOAD_PATH .'/'.$fileName,90);

    //conect to database
    $db= new PDO("".DB_TYPE.":host=".LOCALHOST.";dbname=".DB_NAME."", DB_USERNAME, DB_PASSWORD);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    //insert file name to table

    $query  = $db->prepare("INSERT INTO `uploads` (`upload_name`, `upload_date`) VALUES (?, ?) ");
    $query->bindValue(1, $fileName);
    $query->bindValue(2, date('Y-m-d'));
    try{
        $query->execute();
        }catch(PDOException $e){
    die($e->getMessage());
            }   
   }

  die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');

Do I need to change the `include('config.php);` to have something like:

include('config.php','config2.php','config3.php');

So say I have 3 databases that the uploader needs to have access to.
As a file is added to the loader, the user has to select from a dropdown. The Drop down could be named whatever; db1, db2, and db3.

<select>
  <option value="db1">Images 1</option>
  <option value="db2">Images 2</option>
  <option value="db3">Images 3</option>
</select>

Picture of how I'm thinking I'd like it to work

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
    • ¥15 r语言神经网络自变量重要性分析
    • ¥15 基于双目测规则物体尺寸
    • ¥15 wegame打不开英雄联盟
    • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
    • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
    • ¥30 eclipse开启服务后,网页无法打开
    • ¥30 雷达辐射源信号参考模型
    • ¥15 html+css+js如何实现这样子的效果?
    • ¥15 STM32单片机自主设计