Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if(isset($_SESSION['user'])) {
- ob_start();
- include ('class/upload_class.php'); //classes is the map where the class file is stored (one above the root)
- $max_size = 2048*500; // the max. size for uploading
- $my_upload = new file_upload;
- $my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/cms1/admin/media/"; // "files" is the folder for the uploaded files (you have to create this folder)
- $my_upload->extensions = array(".jpg"); // specify the allowed extensions here
- // $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
- $my_upload->max_length_filename = 50; // change this value to fit your field length in your database (standard 100)
- $my_upload->rename_file = true;
- // You need to modify the settings below...
- $conn = mysql_connect("localhost", "root", "password") or die(mysql_error());
- mysql_select_db("database_Name", $conn) or die(mysql_error());
- // the code to create the test table
- mysql_query("
- CREATE TABLE IF NOT EXISTS file_table (
- id INT NOT NULL AUTO_INCREMENT,
- file_name VARCHAR( 100 ) NOT NULL,
- PRIMARY KEY (id))") or die(mysql_error());
- if(isset($_POST['Submit'])) {
- $my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
- $my_upload->the_file = $_FILES['upload']['name'];
- $my_upload->http_error = $_FILES['upload']['error'];
- $my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
- $my_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
- $new_name = (isset($_POST['name'])) ? $_POST['name'] : "";
- if ($my_upload->upload($new_name)) { // new name is an additional filename information, use this to rename the uploaded file
- $full_path = $my_upload->upload_dir.$my_upload->file_copy;
- $info = $my_upload->get_uploaded_file_info($full_path);
- // ... or do something like insert the filename to the database
- mysql_query(sprintf("INSERT INTO file_table SET file_name = '%s'", $my_upload->file_copy));
- }
- }
- ob_end_flush();
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>CMS Alpha</title>
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <link rel="stylesheet" type="text/css" href="../css/main.css" />
- </head>
- <body>
- <div id="page-wrap">
- <h1>CMS Alpha</h1>
- <h3>Add Images</h3>
- <br />
- <?php include '../nav.php'; ?>
- <p>Max. filesize = <?php echo $max_size; ?> bytes.</p>
- <form name="form1" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['upload/PHP_SELF']; ?>">
- <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>"><br>
- <label for="upload">Select a file...</label><input type="file" name="upload" size="30"><br clear="all">
- <label for="name">New name?</label><input type="text" name="name" size="20">
- (without extension!) <br clear="all">
- <label for="replace">Replace ?</label><input type="checkbox" name="replace" value="y"><br clear="all">
- <label for="check">Validate filename ?</label><input name="check" type="checkbox" value="y" checked><br clear="all">
- <input style="margin-left:120px;" type="submit" name="Submit" value="Submit">
- </form>
- <br clear="all">
- <p><?php echo $my_upload->show_error_string(); ?></p>
- <?php if (isset($info)) echo "<blockquote>".nl2br($info)."</blockquote>"; ?>
- </div>
- </body>
- </html>
- <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement