上传文件时无法访问该网站

时间:2018-12-20 07:10:47

标签: html laravel laravel-5 file-upload

我是新来的,我不知道错误在哪里,我想我已经小心了所有的路线,但仍然不确定。请帮帮我。 所以当我执行'localhost:8000 / uploadfile /'时,它给了我这个错误 无法访问此站点,本地主机拒绝连接。 尝试: 检查连接 检查代理和防火墙 ERR_CONNECTION_REFUSED 当我浏览详细网址时,它给了我: 找不到视图[上传文件] 这是我的表格

<!DOCTYPE HTML>

<html>
<body>
    
    <?php
        echo Form::open(array('url'=>'/uploadfile','files'->'true'));
        echo 'Select the file to upload';
        echo Form::file('image');
        echo Form::submit('upload file');
        echo Form::close();
    
       ?>

 </body>
 </html>

我的控制者是:

    <?php
    namespace App\Http\Controllers;
    use App\files;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Input;
    use App\Http\Controllers\Controller;

    class UploadFileController extends Controller {
        public function index() {
            return view('uploadfile');
                 }
        public function showUploadFile(Request $request) {
             $file = $request->file('image');

             //Display File Name
             echo 'File Name: '.$file->getClientOriginalName();
             echo '<br>';

             //Display File Extension
             echo 'File Extension: '.$file->getClientOriginalExtension();
             echo '<br>';

             //Display File Real Path
             echo 'File Real Path: '.$file->getRealPath();
             echo '<br>';

             //Display File Size
             echo 'File Size: '.$file->getSize();
             echo '<br>';

             //Display File Mime Type
             echo 'File Mime Type: '.$file->getMimeType();

              //Move Uploaded File
              $destinationPath = 'uploads';
              $file->move($destinationPath,$file- 
              >getClientOriginalName());
                           }
               }

最终我的路线         路线:: get('/ uploadfile','UploadFileController @ index');         路线:: post('/ uploadfile','UploadFileController @ showUploadFile');

1 个答案:

答案 0 :(得分:0)

您应该尝试以下操作:

您的查看文件,例如:

路径

yourproject folder/resources/views/uploadfile.blade.php

<form class="form-bordered" action="{{url('/uploadfile')}}" method="POST">
   <div>
       <lable>Select the file to upload</lable>
       <input type="file" name="image">
       <input type="submit" value="upload file">


   </div>

</form>