„Succes!“
, overschrijdt 1 => het „Geuploade dossier upload_max_filesize richtlijn in php.ini“
, overschrijden 2 => het „Geuploade dossier de Max_file_size- richtlijn die in de vorm van HTML“ werd gespecificeerd
, werden 3 => het „Geuploade dossier slechts gedeeltelijk geupload“
, werden 4 => „Geen dossier geupload“
, 6 => die een „tijdelijke omslag“ missen
, kunnen 7 => „dossier aan schijf“ schrijven niet
)
;
// ALS ER NIETS IN $_POST ZIJN, OPGEZET DE VORM VOOR INPUT
als (leeg ($_POST))
{
? >
Upload dossier
Results: File Upload\n";
// ACTIVATE THIS TO SEE WHAT IS COMING THROUGH
// echo ""; var_dump($_FILES); var_dump($_POST); echo " \n";
// ITERATE OVER THE CONTENTS OF $_FILES
foreach ($_FILES as $my_uploaded_file)
{
// SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
$error_code = $my_uploaded_file["error"];
if ($error_code == 4) continue;
// SYNTHESIZE THE NEW FILE NAME
$f_type = trim(strtolower(end (explode( '.', basename($my_uploaded_file['name'] )))));
$f_name = trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));
$my_new_file = getcwd() . '/' . $uploads . '/' . $f_name . '.' . $f_type;
$my_file = $uploads . '/' . $f_name . '.' . $f_type;
// OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
if (!in_array($f_type, $file_exts)) die("Sorry, $f_type files not allowed");
// IF THERE ARE ERRORS
if ($error_code != 0)
{
$error_message = $errors[$error_code];
die("Sorry, Upload Error Code: $error_code: $error_message");
}
// GET THE FILE SIZE
$file_size = number_format($my_uploaded_file["size"]);
// IF THE FILE IS NEW (DOES NOT EXIST)
if (!file_exists($my_new_file))
{
// IF THE MOVE FUNCTION WORKED CORRECTLY
if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
{
$upload_success = 1;
}
// IF THE MOVE FUNCTION FAILED
else
{
$upload_success = -1;
}
}
// IF THE FILE ALREADY EXISTS
else
{
echo " $my_file already exists.\n";
// SHOULD WE OVERWRITE THE FILE? IF NOT
if (empty($_POST["overwrite"]))
{
$upload_success = 0;
}
// IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
else
{
$now = date('Y-m-d');
$my_bak = $my_new_file . '.' . $now . '.bak';
if (!copy($my_new_file, $my_bak))
{
echo " Attempted Backup Failed!\n";
}
if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
{
$upload_success = 2;
}
else
{
$upload_success = -1;
}
}
}
// REPORT OUR SUCCESS OR FAILURE
if ($upload_success == 2) { echo " It has been overwritten.\n"; }
if ($upload_success == 1) { echo " $my_file has been saved.\n"; }
if ($upload_success == 0) { echo " It was NOT overwritten.\n"; }
if ($upload_success < 0) { echo " ERROR: $my_file NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND\n"; }
if ($upload_success > 0)
{
weergalm „geuploade bytes $file_size. \ n“;
als (! chmod ($my_new_file, 0755))
{
echo „ chmod (0755) ONTBROKEN: fileperms () = „;
echo substr (sprintf („%o“, fileperms ($my_new_file)), -4);
}
echo „ Zie het dossier $my_file \ n ";
}
// EIND FOREACH ITERATOR - ELKE HERHALING VERWERKT ÉÉN DOSSIER
}
}
|