hi,
i'm using swfupload for my website and i love it.
but there's one annoying problem: i press the cancel button, the file upload is aborted, but the php script with move_uploaded_file is still called.
so the script moves a file that is only partially uploaded.
as i thought my php script isn't able to check if a file was partially uploaded, i used the sample written by the swfupload team that checks the file in detail. but move_uploaded_file was called too.
so now i'm looking for a solution to this problem!
best regards and thanks in advance,
hnr
My solution
I copied parts of my custom script for an example, but haven't tested the code below. Using this method (check file then copy) solved the problem for me.
$upload_name = "Filedata";
$file_name = $_FILES[$upload_name]['name'];
if ($file_name <> "") {
$file_name = strtolower($file_name);
$file_ext = preg_replace('((.*)(\...*))', '$2', $file_name);
$file_name = preg_replace('((.*)(\...*))', '$1', $file_name);
//Create file with temp name
//Rename after copy and confirming it exists
//Use datetime or random key for unique file
$newfile = "../upload/temp/file_".$file_ext;
$copy = copy($_FILES[$upload_name]['tmp_name'],$newfile);
// check if successfully copied
if ($copy){
//Rename file and move to folder
$finalfile = "../upload/actualfilename".$file_ext;
rename($newfile, $finalfile);
} // copy
} else {
header("HTTP/1.1 500 Internal Server Error");
exit(0);
} // if
//header("HTTP/1.1 200");
echo "File Received";
exit(0);
thanks for your reply, but i
thanks for your reply, but i don't see the solution.
the only thing you're doing is extracting some things and moving the file to a new dir.
where's the check if the file was partially uploaded only?
best regards,
hnr
any idea?
do you still have any ideas?
I have the same problem...
I have the same problem...
My solution
my solution:
<?php
if(isset($_POST['PHPSESSID'])) { session_id($_POST['PHPSESSID']); }
session_start();
$nome = microtime(1);
if(isset($_FILES['Filedata']) && is_uploaded_file($_FILES['Filedata']['tmp_name']) && $_FILES['Filedata']['error'] == 0) {
move_uploaded_file($_FILES['Filedata']['tmp_name'], '../../videos/' . $nome);
$_SESSION['video'] = $nome;
}
exit(0);
?>