Upload mehrerer Dateien in Laravel 4

Hier mein controller-code für das hochladen von mehreren Dateien und ich bin die übergabe der Schlüssel und der Wert von 'Briefträger' - rest-API-client für Google Chrome. Ich bin hinzufügen von mehreren Dateien vom Postboten, aber nur 1 Datei ist immer hochladen.

public function post_files() {
    $allowedExts = array("gif", "jpeg", "jpg", "png","txt","pdf","doc","rtf","docx","xls","xlsx");
    foreach($_FILES['file'] as $key => $abc) {
        $temp = explode(".", $_FILES["file"]["name"]);
        $extension = end($temp);
        $filename= $temp[0];
        $destinationPath = 'upload/'.$filename.'.'.$extension;

        if(in_array($extension, $allowedExts)&&($_FILES["file"]["size"] < 20000000)) {
            if($_FILES["file"]["error"] > 0) {
                echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
            }
            if (file_exists($destinationPath)) {
                echo $filename." already exists. ";
            } else {
                $uploadSuccess=move_uploaded_file($_FILES["file"]["tmp_name"],$destinationPath);
                if( $uploadSuccess ) {
                    $document_details=Response::json(Author::insert_document_details_Call($filename,$destinationPath));
                    return $document_details; //or do a redirect with some message that file was uploaded
                //return Redirect::to('authors')
                } else {
                    return Response::json('error', 400);
                }
            }
        }
    }  
}

Ich habe versucht, diesen code auch, aber es gibt mich Speicherort einer Datei im temporären Ordner

$file = Input::file('file');
            echo count($file);

und
echo count($_FILES['file']);
gibt mir immer 5.Kann mir jemand sagen warum?

... und warum foreach(Input::file('file') as $key => $abc) gibt den Fehler ungültige Argumente

InformationsquelleAutor richa | 2013-08-13
Schreibe einen Kommentar