2016-09-07 4 views
1

Ich möchte mehrere Bilder URL in die Datenbank hochladen, nach dem ich die Datei in einen Upload-Ordner verschieben, dann die Bilder anzeigen und möglicherweise bearbeiten möchten, ändern oder sie entfernen. Ich konnte das mit einem machen, aber ich möchte das für mehrere Bilder machen.So laden Sie mehrere Bilder URL in die Datenbank und verschieben Sie die Dateien in den Ordner

das ist mein html

<section class="form-group"> 
    <section class="col-md-12"> 

       <label for="price">Add Image</label> 

       <input type="file" name="uploadedfile" id="uploadedfile" class="form-control" /> 
       <input type="hidden" name="MAX_FILE_SIZE" value="100000"> 


    </section> 
</section> 

mein PHP-Skript

$target_path="uploads/"; 

$target_path=$target_path.basename($_FILES['uploadedfile']['name']); 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 

    } 

    if($target_path==="uploads/"){ 
$target_path="images/no-thumb.png"; 
     } 



    $query="insert into properties 
    (owner,email,contact,title,location,price,description,property_id,property_type,bedrooms,images,gsize,size,status,post_date) 
values('$name','$email','$contact', 
'$title','$location','$price','$description','$listid',$type','$bedroom','$target_path','$gsize','$size','$status',now())"; 


    $result=mysqli_query($dbc,$query); 
    if($result){ 
    echo '<p class="bg-success alert alert-success text-center">Property Listing Successful</p>'; 
    }else{ 
    echo '<p class="bg-danger alert alert-danger">My bad!!! Something went totally wrong. Try again later while i try to fix it <span class="close pull-right"> <span class="close pull-right"> <a href="#" >&times; </a></span></p>'; 
    } 

`` `

+0

verwenden nur foreach – JYoThI

+0

, die das Problem mit mehreren Bildern? –

+0

(http://stackoverflow.com/questions/9531856/uploading-multiple-images-with-one-input-field) siehe diesen Link –

Antwort

1

Eingabe ändern Jetzt Feld

<input type="file" multiple="true" name="uploadedfile[]" id="uploadedfile" class="form-control" /> 

Oder

<input type="file" multiple="multiple" name="uploadedfile[]" id="uploadedfile" class="form-control" /> 

Sie erhalten ein Array ausgewählter Bilder in $ _FILES. Sie können es durchlaufen und einzeln speichern.

+0

warum nicht? name = "uploadedfile []" – JYoThI

+0

ja, Name muss auch geändert werden. Lass mich meine Antwort bearbeiten. –

0

Hier ist, was Sie tun müssen:

1.Input Name als Array dh name = "inputname []"

2.Input Element multiple = "multiple" muss definiert werden müssen oder einfach nur mehrere

3.In Ihre PHP-Datei verwenden, um die Syntax "$ _FILES [ 'inputname'] [ 'param'] [index]"

4.Make sicher für leere Dateinamen und Pfade zu suchen, Das Array enthält möglicherweise leere Strings

HTML:

input name="upload[]" type="file" multiple="multiple" /> 

PHP:

 // Count # of uploaded files in array 
    $total = count($_FILES['upload']['name']); 

    // Loop through each file 
    for($i=0; $i<$total; $i++) { 
     //Get the temp file path 
     $tmpFilePath = $_FILES['upload']['tmp_name'][$i]; 

     //Make sure we have a filepath 
     if ($tmpFilePath != ""){ 
     //Setup our new file path 
     $newFilePath = "./uploadFiles/" . $_FILES['upload']['name'][$i]; 

     //Upload the file into the temp dir 
     if(move_uploaded_file($tmpFilePath, $newFilePath)) { 

      //Handle other code here 

     } 
     } 
    } 

source

+0

Wie füge ich die Datei-URL in meine Abfrage ein? Welche Variable enthält nun die Datei-URL? Entschuldigung, aber ziemlich Neuling hier –

Verwandte Themen