Simple Upload Script





6
Date Submitted Sun. Oct. 22nd, 2006 5:34 AM
Revision 1 of 1
Beginner kiefpiet
Tags PHP | upload
Comments 2 comments
Simple file upload script.

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>:: badc0de Upload Script</title>
<style>
body {
        background-color: #999;
        color: #CC0000;
}
#txt-input {
        border: 1px solid #000;
        background-color: #C0C0C0;
}

#submit {
        border: 1px solid #000;
        background-color: #C0C0C0;
}
</style>
</head>
<body>
 

<?php

// --- Vars --- //

$upl_path = "./"; // Change this to the directory you wish the uploaded file(s) to be placed in.

if (isset($_POST["bc_upload"])) {

$files = $_FILES['file'];

foreach ($files['name'] as $idx=>$file)
        {

                $file_name = $files['name'][$idx];
                $file_name = strtolower($file_name);
                $file_name = preg_replace('/[^a-z0-9_.]/i', '', $file_name);
                $file_size= intval($files['size'][$idx]);
                $tmp_file = $files['tmp_name'][$idx];

                $copy = copy($tmp_file,$upl_path.$file_name);

                if($copy) { echo ("Files uploaded successfully!<br />\n"); }
                if(!$copy && $file_name != '') { echo ("<b>An error occoured while uploading the files!<br />\n"); }
       
        } // end foreach

        echo ("<a href='". $_SERVER["PHP_SELF"] ."'>Continue...</a>");

} // end if (isset($_POST["bc_upload"])) {

if (!isset($_POST["bc_upload"])) {

        echo ("<form action='". $_SERVER["PHP_SELF"] ."' method='post' enctype='multipart/form-data'>\n");
        echo ("<b>Files To Be Uploaded:</b>\n");
        echo ("<br />\n");
        echo ("<input name='file[]' type='file' id='txt-input' />\n");
        echo ("<br />\n");
        echo ("<input name='file[]' type='file' id='txt-input' />\n");
        echo ("<br />\n");
        echo ("<input name='file[]' type='file' id='txt-input' />\n");
        echo ("<br />\n");
        echo ("<input name='file[]' type='file' id='txt-input' />\n");
        echo ("<br />\n");
        echo ("<input name='file[]' type='file' id='txt-input' />\n");
        echo ("<br /><br />\n");
        echo ("<input name='bc_upload' type='submit' value='Upload' id='submit' />\n");
        echo ("</form>\n");

}

?>
 

</body>
</html>
 

kief piet

Comments

Comments Antisnippet
Sat. Oct. 28th, 2006 3:54 PM    Scripter SCoon
Comments Simple, yes. Secure, no
Thu. Nov. 9th, 2006 2:35 AM    Helper Nico

Voting