document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. session_start();
  3. if(isset($_SESSION[\'user\'])) {
  4.  
  5. ob_start();
  6. include (\'class/upload_class.php\'); //classes is the map where the class file is stored (one above the root)
  7.  
  8. $max_size = 2048*500; // the max. size for uploading
  9.    
  10. $my_upload = new file_upload;
  11.  
  12. $my_upload->upload_dir = $_SERVER[\'DOCUMENT_ROOT\']."/cms1/admin/media/"; // "files" is the folder for the uploaded files (you have to create this folder)
  13. $my_upload->extensions = array(".jpg"); // specify the allowed extensions here
  14. // $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
  15. $my_upload->max_length_filename = 50; // change this value to fit your field length in your database (standard 100)
  16. $my_upload->rename_file = true;
  17.  
  18. // You need to modify the settings below...
  19. $conn = mysql_connect("localhost", "root", "password") or die(mysql_error());
  20. mysql_select_db("database_Name", $conn) or die(mysql_error());
  21.  
  22. // the code to create the test table
  23. mysql_query("
  24.     CREATE TABLE IF NOT EXISTS file_table (
  25.     id INT NOT NULL AUTO_INCREMENT,
  26.     file_name VARCHAR( 100 ) NOT NULL,
  27.     PRIMARY KEY (id))") or die(mysql_error());
  28.        
  29. if(isset($_POST[\'Submit\'])) {
  30.     $my_upload->the_temp_file = $_FILES[\'upload\'][\'tmp_name\'];
  31.     $my_upload->the_file = $_FILES[\'upload\'][\'name\'];
  32.     $my_upload->http_error = $_FILES[\'upload\'][\'error\'];
  33.     $my_upload->replace = (isset($_POST[\'replace\'])) ? $_POST[\'replace\'] : "n"; // because only a checked checkboxes is true
  34.     $my_upload->do_filename_check = (isset($_POST[\'check\'])) ? $_POST[\'check\'] : "n"; // use this boolean to check for a valid filename
  35.     $new_name = (isset($_POST[\'name\'])) ? $_POST[\'name\'] : "";
  36.     if ($my_upload->upload($new_name)) { // new name is an additional filename information, use this to rename the uploaded file
  37.         $full_path = $my_upload->upload_dir.$my_upload->file_copy;
  38.         $info = $my_upload->get_uploaded_file_info($full_path);
  39.        
  40.         // ... or do something like insert the filename to the database
  41.         mysql_query(sprintf("INSERT INTO file_table SET file_name = \'%s\'", $my_upload->file_copy));
  42.    
  43.        
  44.     }
  45.  
  46. }
  47. ob_end_flush();
  48. ?>
  49. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  50. <html xmlns="http://www.w3.org/1999/xhtml">
  51. <head>
  52. <title>CMS Alpha</title>
  53. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  54. <link rel="stylesheet" type="text/css" href="../css/main.css" />
  55. </head>
  56. <body>
  57. <div id="page-wrap">
  58.   <h1>CMS Alpha</h1>
  59.   <h3>Add Images</h3>
  60.   <br />
  61.    <?php include \'../nav.php\'; ?>
  62.  
  63. <p>Max. filesize = <?php echo $max_size; ?> bytes.</p>
  64. <form name="form1" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER[\'upload/PHP_SELF\']; ?>">
  65.   <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>"><br>
  66.   <label for="upload">Select a file...</label><input type="file" name="upload" size="30"><br clear="all">
  67.   <label for="name">New name?</label><input type="text" name="name" size="20">
  68.   (without extension!) <br clear="all">
  69.   <label for="replace">Replace ?</label><input type="checkbox" name="replace" value="y"><br clear="all">
  70.   <label for="check">Validate filename ?</label><input name="check" type="checkbox" value="y" checked><br clear="all">
  71.   <input style="margin-left:120px;" type="submit" name="Submit" value="Submit">
  72. </form>
  73. <br clear="all">
  74. <p><?php echo $my_upload->show_error_string(); ?></p>
  75. <?php if (isset($info)) echo "<blockquote>".nl2br($info)."</blockquote>"; ?>
  76. </div>
  77. </body>
  78. </html>
  79. <?php } ?>
');