Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php ob_start();
- require_once("users/includes/frontend/header.php");
- require_once("users/includes/frontend/navigation.php");
- error_reporting(E_ALL);
- // set variables
- $path_type = Input::get('path');
- $dir_dest = (isset($_GET['dir']) ? $_GET['dir'] : $path_type);
- $dir_pics = (isset($_GET['pics']) ? $_GET['pics'] : $dir_dest);
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <meta http-equiv=content-type content="text/html; charset=UTF-8">
- <head>
- <title>class.php.upload test forms</title>
- <style>
- body {
- }
- p.result {
- width: 50%;
- margin: 15px 0px 25px 0px;
- padding: 0px;
- clear: right;
- }
- img {
- float: right;
- background: url(bg.gif);
- }
- fieldset {
- width: 50%;
- margin: 15px 0px 25px 0px;
- padding: 15px;
- }
- legend {
- font-weight: bold;
- }
- fieldset p {
- font-size: 70%;
- font-style: italic;
- }
- .button {
- text-align: right;
- }
- .button input {
- font-weight: bold;
- }
- </style>
- </head>
- <body>
- <?php
- if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'image') {
- // ---------- IMAGE UPLOAD ----------
- // we create an instance of the class, giving as argument the PHP object
- // corresponding to the file field from the form
- // All the uploads are accessible from the PHP object $_FILES
- $handle = new Upload($_FILES['my_field']);
- // then we check if the file has been uploaded properly
- // in its *temporary* location in the server (often, it is /tmp)
- if ($handle->uploaded) {
- // yes, the file is on the server
- // below are some example settings which can be used if the uploaded file is an image.
- $handle->image_resize = true;
- $handle->image_ratio_y = true;
- $handle->image_x = 700;
- // now, we start the upload 'process'. That is, to copy the uploaded file
- // from its temporary location to the wanted location
- // It could be something like $handle->Process('/home/www/my_uploads/');
- $handle->Process($dir_dest);
- // we check if everything went OK
- if ($handle->processed) {
- // everything was fine !
- $old_photo = Input::get('old_photo');
- $path_type = Input::get('path');
- $id = Input::get('id');
- if($old_photo !='smile.png'){
- unlink($path_type.'/'. $old_photo);}
- $db->update($path_type,$id,['photo'=>$handle->file_dst_name]);
- Redirect::to('cpanel.php');
- } else {
- // one error occured
- echo '<p class="result">';
- echo ' <b>File not uploaded to the wanted location</b><br />';
- echo ' Error: ' . $handle->error . '';
- echo '</p>';
- }
- // we delete the temporary files
- $handle-> Clean();
- } else {
- // if we're here, the upload file failed for some reasons
- // i.e. the server didn't receive the file
- echo '<p class="result">';
- echo ' <b>File not uploaded on the server</b><br />';
- echo ' Error: ' . $handle->error . '';
- echo '</p>';
- }
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment