Pluplod 2.1.2上传文件并保存到mysql

时间:2015-01-23 20:23:39

标签: mysql plupload

我有一个以前版本的plupload的代码可以正常工作。它会上传文件并将其保存到mysql数据库。

我正在尝试将其升级到pluplod 2.1.2的最新版本。我可以上传文件但是没有将数据保存到mysql。

这是我的代码。请任何帮助将非常好。我查看了所有的pupload论坛,但我没有看到这个新版本的答案。

非常感谢。

enter code here
<?php
/**
 * upload.php
 *
 * Copyright 2013, Moxiecode Systems AB
 * Released under GPL License.
 *
 * License: http://www.plupload.com/license
 * Contributing: http://www.plupload.com/contributing
 */

#!! IMPORTANT: 
#!! this file is just an example, it doesn't incorporate any security checks and 
#!! is not recommended to be used in production environment as it is. Be sure to 
#!! revise it and customize to your needs.


// Make sure file is not cached (as it happens for example on iOS devices)
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


$id= $_SESSION['$ide'];
include "mysqlconnection.php";

$ide = $_GET['i'];

session_start();


/* 
// Support CORS
header("Access-Control-Allow-Origin: *");
// other CORS headers if any...
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    exit; // finish preflight CORS requests here
}
*/

// 5 minutes execution time
@set_time_limit(5 * 60);

// Uncomment this one to fake upload time
// usleep(5000);

// Settings
//$targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
//$targetDir = 'uploads';
$targetDir = '../images';

$cleanupTargetDir = true; // Remove old files
$maxFileAge = 5 * 3600; // Temp file age in seconds


// Create target dir
if (!file_exists($targetDir)) {
    @mkdir($targetDir);
}

// Get a file name
if (isset($_REQUEST["name"])) {
    $fileName = $_REQUEST["name"];
} elseif (!empty($_FILES)) {
    $fileName = $_FILES["file"]["name"];
} else {
    $fileName = uniqid("file_");
}

$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;





$path1= $filename;
//$ref= '98-prueba1';
//$id='98';

//echo '$filePath='.$filePath.'<br/>';
//echo '$filename='.$filename.'<br/>';
//echo '$path1='.$path1.'<br/>';
//echo '$ide='.$ide.'<br/>';    



// Chunking might be enabled
$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($targetDir) || !$dir = opendir($targetDir)) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
    }

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

        // If temp file is current file proceed to the next
        if ($tmpfilePath == "{$filePath}.part") {
            continue;
        }

        // Remove temp file if it is older than the max age and is not the current file
        if (preg_match('/\.part$/', $file) && (filemtime($tmpfilePath) < time() - $maxFileAge)) {
            @unlink($tmpfilePath);
        }
    }
    closedir($dir);
}   


// Open temp file
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);

// Check if file has been uploaded
if (!$chunks || $chunk == $chunks - 1) {
    // Strip the temp .part suffix off 
    rename("{$filePath}.part", $filePath);




//This part is what I added:
if($fileName!=$_SESSION['unique_name']){
    $time=date(DATE_ATOM);
    $con = mysql_connect("mylocalhost","user","pass");
    if (!$con){ die('Could not connect: ' . mysql_error()); }
    mysql_select_db("bbdd", $con);
   // mysql_query("UPDATE table SET picture1='picture4 Jeh' WHERE id='$id'");

    //$prefijo1 = substr(md5(uniqid(rand())),0,4);
    //$path1 = 'imagenes/viviendas/'. $prefijo1.'_'.$fileName;
    $path1 = 'images/'.$fileName;




$sacaid=mysql_query("SELECT * FROM table WHERE id='$ide' ");
if ($row=mysql_fetch_array($sacaid)) {
$id = $row["id"];
$refe = $row["refe"];
//$ref = $row["referencia"];
$picture1 = $row['picture1'];
$picture2 = $row['picture2'];
$picture3 = $row['picture3'];
$picture4 = $row['picture4'];
$picture5 = $row['picture5'];
$picture6 = $row['picture6'];
$picture7 = $row['picture7'];
$picture8 = $row['picture8'];
$picture9 = $row['picture9'];
$picture10 = $row['picture10'];
$picture11 = $row['picture11'];
$picture12 = $row['picture12'];
$picture13 = $row['picture13'];
$picture14 = $row['picture14'];
$picture15 = $row['picture15'];
$picture16 = $row['picture16'];
}

if (strlen($picture1) < 25) { 
mysql_query("UPDATE table SET picture1='$path1' WHERE id='$ide' ");  //esto si que lo hace
}
else { //else1
if (strlen($picture2) < 25) { 
mysql_query("UPDATE table SET picture2='$path1' WHERE id='$ide' ");
}
else { //else2
if (strlen($picture3) < 25) { 
mysql_query("UPDATE table SET picture3='$path1' WHERE id='$ide' ");
}
else { //else3
if (strlen($picture4) < 25) { 
mysql_query("UPDATE table SET picture4='$path1' WHERE id='$ide' ");
}
else { //else4
if (strlen($picture5) < 25) { 
mysql_query("UPDATE table SET picture5='$path1' WHERE id='$ide' ");
}
else { //else5
if (strlen($picture6) < 25) { 
mysql_query("UPDATE table SET picture6='$path1' WHERE id='$ide' ");
}
 else { //else6
if (strlen($picture7) < 25) { 
mysql_query("UPDATE table SET picture7='$path1' WHERE id='$ide' ");
}
else { //else7
if (strlen($picture8) < 25) { 
mysql_query("UPDATE table SET picture8='$path1' WHERE id='$ide' ");
}
else { //else8
if (strlen($picture9) < 25) { 
mysql_query("UPDATE table SET picture9='$path1' WHERE id='$ide' ");
}
else { //else9
if (strlen($picture10) < 25) { 
mysql_query("UPDATE table SET picture10='$path1' WHERE id='$ide' ");
}
else { //else10
if (strlen($picture11) < 25) { 
mysql_query("UPDATE table SET picture11='$path1' WHERE id='$ide' ");
}
else { //else11
if (strlen($picture12) < 25) { 
mysql_query("UPDATE table SET picture12='$path1' WHERE id='$ide' ");
}
else { //else12
if (strlen($picture13) < 25) { 
mysql_query("UPDATE table SET picture13='$path1' WHERE id='$ide' ");
}
else { //else13
if (strlen($picture14) < 25) { 
mysql_query("UPDATE table SET picture14='$path1' WHERE id='$ide' ");
}
else { //else14
if (strlen($picture15) < 25) { 
mysql_query("UPDATE table SET picture15='$path1' WHERE id='$ide' ");
}
else { //else15
if (strlen($picture16) < 25) { 
mysql_query("UPDATE table SET picture16='$path1' WHERE id='$ide' ");
} 

} // fin else 1
} // fin else 2
} // fin else 3
} // fin else 4
} // fin else 5
} // fin else 6
} // fin else 7
} // fin else 8
} // fin else 9
} // fin else 10
} // fin else 11
} // fin else 12
} // fin else 13
} // fin else 14
} // fin else 15    

echo '$path1='.$path1.'<br/>';
echo '$ide='.$ide.'<br/>';  



    mysql_close($con);
    $_SESSION['unique_name']=$fileName;
      };
//End what I added




} // ENDING Check if file has been uploaded





// Return Success JSON-RPC response
die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');

?>

0 个答案:

没有答案