<!DOCTYPE html>
<html>
<body>
<?php 
$name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
$location = 'uploads/';
$meta = get_meta_tags($location . $name);
if (MOVE_UPLOADED_FILE($tmp_name, $location . $name)) {
    echo "uploaded";
    echo $meta['size'];
} else {
    echo "not uploaded!!";
}
?>
<form action="filehandling2.php"  enctype="multipart/form-data" method="post" >
<input type="file" name="file"><br><br>
<input type="submit" value="submit">
</form>
</body>
</html>
示例#2
0
文件: dirtree.php 项目: rgevaert/ABCD
function UPLOAD2($NODE)
{
    /*
    This is the second phase of the upload file process in this phase all the
    process is checked against errors.
    If the things go well the process is terminated with the move of the uploaded
    file to the directory chosen.
    If the things go bad the process is aborted and the uploaded file is erased.
    */
    global $ACTION;
    $UPLOAD_DIR = BUILD_PATH($NODE);
    PAGE_HEADER("DIRECTORY MANAGER - DIRTREEVIEW", "UPLOAD FILE - CKECK PHASE", "", "");
    ?>
   <Table WIDTH=100% BORDER=0 CELLPADDING=8 CELLSPACING=0 class=td>
        <Tr>
            <Td VALIGN=top ALIGN=left>
                <Center>
                <Font FACE=tahoma>
   <?php 
    $ERROR_FUNCTION = false;
    // File Size in bytes (change this value to fit your need)
    echo "<H3>Biggest File Size=" . $_SESSION['Size_Bytes'] . "</H3></font></td></tr>";
    echo "<H3>Upload Dir=" . $UPLOAD_DIR . "</H3></font></td></tr>";
    if ($_SESSION['File_Extension'] != "") {
        echo "<tr><td><CENTER><H3>Extensions allowed= " . $_SESSION['File_Extension'] . "</H3></td></tr>";
    }
    // check if the directory exists or not with the server path added
    $REAL_UPLOAD_DIR = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRNAME($_SESSION['Server_Path'])) . DIRECTORY_SEPARATOR . $UPLOAD_DIR;
    if (!IS_DIR($REAL_UPLOAD_DIR)) {
        echo "<tr><td><CENTER><H3>The directory where to upload doesn't exist, please verify.. </H3></td></tr>";
        $ERROR_FUNCTION = true;
    } else {
        // check if the directory is writable.
        if (!IS_WRITEABLE($REAL_UPLOAD_DIR)) {
            echo "<tr><td><CENTER><H3>The directory where to upload is NOT writable, please put the write attribute permissions on </H3></td></tr>";
            $ERROR_FUNCTION = true;
        } else {
            // check if no file selected.
            if (!IS_UPLOADED_FILE($_FILES['filetoupload']['tmp_name'])) {
                echo "<tr><td><CENTER><H3>Error: Please select a file to upload!. </H3></td></tr>";
                $ERROR_FUNCTION = true;
            } else {
                // Get the Size of the File
                $SIZE = $_FILES['filetoupload']['size'];
                // Make sure that file size is correct
                if ($SIZE > $_SESSION['Size_Bytes']) {
                    $KB = $_SESSION['Size_Bytes'] / 1024;
                    echo "<tr><td><CENTER><H3>File Too Large. File must BE LESS THAN <b>{$KB}</b> KB. </H3></td></tr>";
                    $ERROR_FUNCTION = true;
                } else {
                    // check file extension
                    if ($_SESSION['File_Extension'] != "" && !IS_FILE_TO_DISPLAY($_FILES['filetoupload']['name']) != false) {
                        echo "<tr><td><CENTER><H3>Wrong file extension. </H3></td></tr>";
                        $ERROR_FUNCTION = true;
                    } else {
                        // $Filename will hold the value of the file name submitted from the form.
                        $FILENAME = $_FILES['filetoupload']['name'];
                        // Check if file is Already EXISTS.
                        if (File_Exists($REAL_UPLOAD_DIR . DIRECTORY_SEPARATOR . $FILENAME)) {
                            echo "<tr><td><CENTER><H3>Sorry but the file named <b>" . $FILENAME . "</b> already exists in the server, please change the filename before UPLOAD</H3></td></tr>";
                            $ERROR_FUNCTION = true;
                        } else {
                            // Move the File to the Directory choosen + the server path determined
                            // move_uploaded_file('filename','destination') Moves afile to a new location.
                            if (!MOVE_UPLOADED_FILE($_FILES['filetoupload']['tmp_name'], $REAL_UPLOAD_DIR . DIRECTORY_SEPARATOR . $FILENAME)) {
                                // Print error msg.
                                echo "<tr><td><CENTER><H3>There was a problem moving your file. </H3></td></tr>";
                                $ERROR_FUNCTION = true;
                            } else {
                                // tell the user that the file has been uploaded.
                                echo "<tr><td><CENTER><H3>File SUCCESFULLY uploaded! </H3></td></tr>";
                            }
                        }
                    }
                }
            }
        }
    }
    ?>
       <Tr>
            <Td>
            <Center>
            <Font FACE=tahoma>
           <Form NAME="FormUploadFile2" METHOD="post" ENCTYPE="multipart/form-data" ACTION="<?php 
    echo $_SERVER['PHP_SELF'];
    ?>
">
                <Table ALIGN=center BORDER=0 class=td>
                    <Tr>
                        <Input TYPE="hidden" NAME="FILE_EXTENSION" VALUE="<?php 
    echo $_SESSION['File_Extension'];
    ?>
">
                        <Input TYPE="hidden" NAME="NODE" VALUE="<?php 
    echo $NODE;
    ?>
">
                        <Input TYPE="hidden" NAME="ACTION" VALUE="upload3">
	<?php 
    if ($ERROR_FUNCTION) {
        ?>
 <Td><Input TYPE="Submit" NAME="submit" VALUE="   Cancel  "></Td><?php 
    } else {
        ?>
 <Td><Input TYPE="Submit" NAME="submit" VALUE="   Accept  "></Td><?php 
    }
    ?>
                    </Tr>
                </Table>
            </Form>
            </Td>
        </Tr>
    </Table>
   <?php 
    PAGE_FOOTER("", "");
    exit;
}