2016-08-11 4 views
0

Ich habe ein Formular zum Hochladen von Bild mit dem Titel auf den Server und nach erfolgreichem Upload, wird es Sie auf eine andere Seite umleiten. Während des Hochladens des Bildes möchte ich dort die Fortschrittsleiste anzeigen und nach erfolgreichem Hochladen auch auf eine andere Seite umleiten.
Ich weiß über PHP und googelte auch über progressbar. Alle Links beziehen sich nur auf Javascript und ich bin neu in Javascript. Kann mir bitte jemand dabei helfen? Hier ist upload.php enthält FormWie füge ich Fortschrittsbalken beim Hochladen von Formular mit PHP

<form action="newupload.php" enctype="multipart/form-data" method="post"> 
    <div class="form-group"> 
     <div id="image-cropper"> 
      <div class="cropit-preview"></div> 
      <input type="file" name="user_image" class="cropit-image-input" style="font-weight: bold;" /> 
     </div> 
    </div> 
    <div class="form-group"> 
     <input type="text" name="title" class="input-round big-input" id="title-modal" placeholder="Enter your Image Title" required/> 
     <input type="hidden" name="category" value="<?php echo $category; ?>" /> 
     <input type="hidden" name="hashtag" value="<?php echo $hashtag; ?>" /> 
    </div> 
    <div class="form-group"> 
     <!-- required --> 
     <span class="required margin-three">*Please complete all fields correctly</span> 
     <!-- end required --> 
     <p class="text-center"> 
      <!-- button --> 
      <button class="btn btn-black no-margin-bottom btn-medium btn-round no-margin-top" type="submit">Submit</button> 
      <!-- end button --> 
     </p> 
    </div> 
</form> 

Hier ist newupload.php Datei für Umzug und Update-Datenbank

<?php 
define("MAX_SIZE", "400"); 
include ('mysqli_connect.php'); 

session_start(); 
$email = $_SESSION['user_email']; 
$q = "select * from user where u_email='$email'"; 
$qres = mysqli_query($dbc, $q); 
$qrow = mysqli_fetch_array($qres, MYSQLI_ASSOC); 
$u_id = $qrow['u_id']; 

function getExtension($str) 
    { 
    $i = strrpos($str, "."); 
    if (!$i) 
    { 
    return ""; 
    } 

    $l = strlen($str) - $i; 
    $ext = substr($str, $i + 1, $l); 
    return $ext; 
    } 

if ($_SERVER["REQUEST_METHOD"] == "POST") 
    { 
    $image = $_FILES['user_image']['name']; 
    $uploadedfile = $_FILES['user_image']['tmp_name']; 
    $image_title = $_POST['title']; 
    $category = $_POST['category']; 
    $hashtag = $_POST['hashtag']; 
    if ($image) 
    { 
    $filename = stripslashes($_FILES['user_image']['name']); 
    $extension = getExtension($filename); 
    $extension = strtolower($extension); 
    if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
     { 
     echo ' Unknown Image extension '; 
     $errors = 1; 
     } 
     else 
     { 
     $size = filesize($_FILES['user_image']['tmp_name']); 
     if ($extension == "jpg" || $extension == "jpeg") 
     { 
     $uploadedfile = $_FILES['user_image']['tmp_name']; 
     $src = imagecreatefromjpeg($uploadedfile); 
     } 
     else 
     if ($extension == "png") 
     { 
     $uploadedfile = $_FILES['user_image']['tmp_name']; 
     $src = imagecreatefrompng($uploadedfile); 
     } 
     else 
     { 
     $src = imagecreatefromgif($uploadedfile); 
     } 

     $maxwidth = 800; 
     list($width, $height) = getimagesize($uploadedfile); 
     if ($width >= $maxwidth) 
     { 
     $newwidth = 800; 
     $newheight = ($maxwidth/$width) * $height; 
     } 
     else 
     { 
     $newwidth = $width; 
     $newheight = $height; 
     } 

     $tmp = imagecreatetruecolor($newwidth, $newheight); 
     imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 
     $t = uniqid(); 
     $filenamee = 'user-' . $t; 
     $path = 'uploaded/'; 
     $filename = $path . $filenamee . ".jpg"; 
     move_uploaded_file($_FILES['user_image']['tmp_name'], $filename); 
     (u_id, s_category, s_title, s_upload, s_maxupload) values('$u_id', '$category', '$image_title', '$filename', '$mfilename') "; 
$query="insertintoselfiepost(u_id, s_category, s_title, s_upload, s_hashtag, upload_time) values('$u_id', '$category', '$image_title', '$filename', '$hashtag', now()) "; 
    $res=mysqli_query($dbc,$query); 
    if($res){ 

     header('Location:home.php?insert=1'); 
    } else{ 
      header('Location:home.php?insert=0'); 
     } 
    }} 
    } 
    ?> 
+0

http://stackoverflow.com/questions/849237/upload-progress-bar-in-php dies möglicherweise –

+0

Mögliche Duplizierung http helfen: // Stackoverflow. com/questions/26674575/php-upload-extract-und-progressbar/26679480 # 26679480 – NewToJS

+0

@ VishnuBhadoriya ich ging bereits durch den Link .. danke –

Antwort

Verwandte Themen