这是我用于上传多个文件的控制器代码,我从Google Chrome上的'postman'rest API客户端传递密钥和值.我正在从邮递员添加多个文件,但只有1个文件正在上传.
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 …
Run Code Online (Sandbox Code Playgroud) 我已经在Laravel 4中的控制器和路由文件中对此进行了编码,并遇到了诸如"在非对象上调用成员函数move()"之类的错误,
"Call to a member function getClientOriginalName() on a non-object"
Run Code Online (Sandbox Code Playgroud)
控制器:
class AuthorsController extends BaseController{
public $restful = true;
public function post_files()
{
$input = Input::all();
$rules = array(
'file' => 'image|mime:jpg,gif,png|max:3000',
);
$validation = Validator::make($input, $rules);
if ($validation->fails())
{
return Response::make($validation->errors->first(), 400);
}
$file = Input::file('file'); // your file upload input field in the form should be named 'file'
$destinationPath = 'public/uploads/'.str_random(8);
// $filename = $file->getClientOriginalName();
$filename = $file['name'];
//$extension =$file->getClientOriginalExtension(); //if you need extension of the file …
Run Code Online (Sandbox Code Playgroud) 我不知道如何维护和使用会话.因为我是laravel 4的新手
我创建了一个表如下:
class Sessions extends Migration
{
Schema::create('sessions', function($table)
{
$table->string('id')->unique();
$table->text('payload');
$table->integer('last_activity');
});
}
Run Code Online (Sandbox Code Playgroud)
Plz帮助我尽快详细解释过程.帮助将不胜感激.