Errore configurazione plupload

Cristiano Landi

Nuovo Utente
14 Gen 2014
1
0
0
Ho fatto una specie di "server interno" con un computer (windows) formato da una pagina per il download e uno per l'upload. Quest'ultima pagina mi da un problema: il trasferimento avviene con successo, ma i file a fine trasferimento non vengono rinominati e perdono il nome e il formato. Per fare la pagina ho usato il codice di esempio di plupload... questo problema accade con i file di grande dimensione (100 o più megabyte), ma non con quelli più piccoli.

Ecco i 3 codici contenuti nella cartella di esempio da me modificati:
Quello html:
HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>

<title>Plupload - Custom example</title>

<!-- production -->
<script type="text/javascript" src="../js/plupload.full.min.js"></script>


<!-- debug 
<script type="text/javascript" src="../js/moxie.js"></script>
<script type="text/javascript" src="../js/plupload.dev.js"></script>
-->

</head>
<body style="font: 13px Verdana; background: #eee; color: #333">

<h1>Custom example</h1>

<p>Shows you how to use the core plupload API.</p>

<div id="filelist">Your browser doesn't have Flash, Silverlight or HTML5 support.</div>
<br />

<div id="container">
    <a id="pickfiles" href="javascript:;">[Select files]</a> 
    <a id="uploadfiles" href="javascript:;">[Upload files]</a>
</div>

<br />
<pre id="console"></pre>


<script type="text/javascript">
// Custom example logic

var uploader = new plupload.Uploader({
	runtimes : 'html5,flash,silverlight,html4',
	browse_button : 'pickfiles', // you can pass in id...
	container: document.getElementById('container'), // ... or DOM Element itself
	url : 'upload.php',
	flash_swf_url : '../js/Moxie.swf',
	silverlight_xap_url : '../js/Moxie.xap',
	
	filters : {
		max_file_size : '100000000mb',
		mime_types: [
			{title : "Image files", extensions : "jpg,gif,png"},
			{title : "Zip files", extensions : "zip"}
		]
	},

	init: {
		PostInit: function() {
			document.getElementById('filelist').innerHTML = '';

			document.getElementById('uploadfiles').onclick = function() {
				uploader.start();
				return false;
			};
		},

		FilesAdded: function(up, files) {
			plupload.each(files, function(file) {
				document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
			});
		},

		UploadProgress: function(up, file) {
			document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
		},

		Error: function(up, err) {
			document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
		}
	}
});

uploader.init();

</script>
</body>
</html>

Quello upload.php
PHP:
<?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");

/* 
// 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(10000 * 60);

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

// Settings
$targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
//$targetDir = 'uploads';
$cleanupTargetDir = true; // Remove old files
$maxFileAge = 100 * 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;

// 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);
}

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


infine dump.php
PHP:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Plupload - Form dump</title>
</head>
<body style="font: 13px Verdana; background: #eee; color: #333">
	
<h1>Post dump</h1>

<p>Shows the form items posted.</p>

<table>
	<tr>
		<th>Name</th>
		<th>Value</th>
	</tr>
	<?php $count = 0; foreach ($_POST as $name => $value) { ?>
	<tr class="<?php echo $count % 2 == 0 ? 'alt' : ''; ?>">
		<td><?php echo htmlentities(stripslashes($name)) ?></td>
		<td><?php echo nl2br(htmlentities(stripslashes($value))) ?></td>
	</tr>
	<?php } ?>
</table>

</body>
</html>


Perché i file più grandi non si rinominano?
 
Discussioni simili
Autore Titolo Forum Risposte Data
M Errore configurazione motion detection nvr Hikvision DS-7616 IP Cam e Videosorveglianza 0
E Errore configurazione 18 Dahua Dome POE IP Cam e Videosorveglianza 6
F Errore configurazione APACHE con PHP Apache 1
K Inserimento query Errore 1366 PHP 4
F errore 1062 su campo nuovo MySQL 4
N Errore interno Access MS Access 2
R mi da errore dove inizia il while PHP 1
R Recupero di permalink di un sito che è stato eliminato per errore WordPress 5
R Yoast SEO errore semafori sempre rossi SEO e Posizionamento 0
S Visualizza l'errore di creazione in MSSQL Database 4
simgia Cordova errore quando cerco di emulare o creare la app Sviluppo app per Android 2
P Errore nell'indirizzo degli elementi HTML e CSS 2
Jensen Errore di sintassi con DELETE PHP 3
H Errore su array associativo PHP 1
FDF182 ERRORE 1292 PHP 4
P errore 404 con javascript Javascript 2
felino Windows 7: errore 80072EFE su Windows Update Windows e Software 1
A errore http://datatables.net/tn/7 PHP 4
M Errore visualizzazione meta tag title e description SEO e Posizionamento 1
A Errore durante il salvataggio Photoshop 0
voldemort [c] Errore di segmentazione (core dump creato) C/C++ 1
T SSD - errore sistema Hardware 2
R Navigare sito con cURL, mi restituisce errore PHP 0
L File CSV con app inventor da errore Sviluppo app per Android 2
A Errore visualizzazione selezione testo Photoshop 0
I Postman 400 Errore di richiesta non valida Programmazione 0
S Errore PHP - Notice: Undefined index ... PHP 14
U Campo vuoto data errore Fatal error: PHP 2
R Errore UPDATE tabella mysql PHP 1
R W10 Segnalazione di errore su terminale USB Windows e Software 0
G non riesco a capire quale sia l'errore [SQL] MySQL 2
I Errore 80040220 nella newsletter con paginazione Classic ASP 0
E Errore di lettura php in html PHP 8
A php metodo post jquery non da mai errore jQuery 4
W Errore di run-time di Microsoft VBScript error '800a0035' Impossibile trovare il file Classic ASP 0
B Errore unexpected '$variabile' (T_VARIABLE) in your code on line PHP 2
M errore dopo passaggio Php 7.2 PHP 6
S -> Errore PHP 8
S Errore "ftp_put(): Can't open that file: Permission denied" PHP 1
P Errore telecamere hdcvi dahua IP Cam e Videosorveglianza 16
L form multipla php sql,errore in inserimento MySQL 0
M Errore JavaScript per php [objeto HTMLParagraphElement] PHP 0
F [PHP]Errore registrazione PHP 8
MarcoGrazia [PHP] Download di file con errore all'interno. PHP 1
V [ORACLE] Errore ora-06512 at sys.utl_file Oracle 0
A [WordPress] Errore Plugin WordPress 0
P [WordPress] Messaggio di errore in file style.css WordPress 0
G [Javascript] Errore inserimento dati Backend Node.js e workbench Javascript 1
M [PHP] WS-Security errore PHP 0
M [PHP] Errore di percorso, file not found PHP 3

Discussioni simili