Advertisement
firestorm_dev

userspice upload

May 14th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php ob_start();
  2. require_once("users/includes/frontend/header.php");
  3. require_once("users/includes/frontend/navigation.php");
  4. error_reporting(E_ALL);
  5.  
  6. // set variables
  7. $path_type = Input::get('path');
  8. $dir_dest = (isset($_GET['dir']) ? $_GET['dir'] : $path_type);
  9. $dir_pics = (isset($_GET['pics']) ? $_GET['pics'] : $dir_dest);
  10.  
  11. ?>
  12.  
  13.  
  14. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  15. <html xmlns="http://www.w3.org/1999/xhtml">
  16. <meta http-equiv=content-type content="text/html; charset=UTF-8">
  17. <head>
  18.     <title>class.php.upload test forms</title>
  19.  
  20.     <style>
  21.         body {
  22.         }
  23.         p.result {
  24.           width: 50%;
  25.           margin: 15px 0px 25px 0px;
  26.           padding: 0px;
  27.           clear: right;
  28.         }
  29.         img {
  30.           float: right;
  31.           background: url(bg.gif);
  32.         }
  33.         fieldset {
  34.           width: 50%;
  35.           margin: 15px 0px 25px 0px;
  36.           padding: 15px;
  37.         }
  38.         legend {
  39.           font-weight: bold;
  40.         }
  41.         fieldset p {
  42.           font-size: 70%;
  43.           font-style: italic;
  44.         }
  45.         .button {
  46.           text-align: right;
  47.         }
  48.         .button input {
  49.           font-weight: bold;
  50.         }
  51.     </style>
  52. </head>
  53.  
  54. <body>
  55. <?php
  56. if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'image') {
  57.  
  58.     // ---------- IMAGE UPLOAD ----------
  59.  
  60.     // we create an instance of the class, giving as argument the PHP object
  61.     // corresponding to the file field from the form
  62.     // All the uploads are accessible from the PHP object $_FILES
  63.     $handle = new Upload($_FILES['my_field']);
  64.  
  65.     // then we check if the file has been uploaded properly
  66.     // in its *temporary* location in the server (often, it is /tmp)
  67.     if ($handle->uploaded) {
  68.  
  69.         // yes, the file is on the server
  70.         // below are some example settings which can be used if the uploaded file is an image.
  71.         $handle->image_resize            = true;
  72.         $handle->image_ratio_y           = true;
  73.         $handle->image_x                 = 700;
  74.  
  75.         // now, we start the upload 'process'. That is, to copy the uploaded file
  76.         // from its temporary location to the wanted location
  77.         // It could be something like $handle->Process('/home/www/my_uploads/');
  78.         $handle->Process($dir_dest);
  79.  
  80.         // we check if everything went OK
  81.         if ($handle->processed) {
  82.             // everything was fine !
  83.         $old_photo = Input::get('old_photo');
  84.         $path_type = Input::get('path');
  85.         $id = Input::get('id');
  86.         if($old_photo !='smile.png'){
  87.         unlink($path_type.'/'. $old_photo);}
  88.         $db->update($path_type,$id,['photo'=>$handle->file_dst_name]);
  89.         Redirect::to('cpanel.php');
  90.  
  91.  
  92.         } else {
  93.             // one error occured
  94.             echo '<p class="result">';
  95.             echo '  <b>File not uploaded to the wanted location</b><br />';
  96.             echo '  Error: ' . $handle->error . '';
  97.             echo '</p>';
  98.         }
  99.  
  100.  
  101.         // we delete the temporary files
  102.         $handle-> Clean();
  103.  
  104.     } else {
  105.         // if we're here, the upload file failed for some reasons
  106.         // i.e. the server didn't receive the file
  107.         echo '<p class="result">';
  108.         echo '  <b>File not uploaded on the server</b><br />';
  109.         echo '  Error: ' . $handle->error . '';
  110.         echo '</p>';
  111.     }
  112.  
  113.  
  114. }
  115. ?>
  116. </body>
  117.  
  118. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement