2016-02-15 59 views
0

我用,Laravel 5 |圖片上傳|不能讓上傳可變

$up = request::file('image')->move('../public/images'); 

到上傳圖像到「公共/圖片」目錄中的DATAS。

我試着通過使用「dd()」知道「$ up」的數據。

我得到DATAS如,

UploadedFile {#183 ▼ 
-test: false 
-originalName: "Brackpoints.png" 
-mimeType: "image/png" 
-size: 148276 
-error: 0 
    path: "/tmp" 
    filename: "phpmU8PvU" 
    basename: "phpmU8PvU" 
    pathname: "/tmp/phpmU8PvU" 
    extension: "" 
    realPath: "/tmp/phpmU8PvU" 
    aTime: 2016-02-15 13:57:39 
    mTime: 2016-02-15 13:57:39 
    cTime: 2016-02-15 13:57:39 
    inode: 1443211 
    size: 148276 
    perms: 0100600 
    owner: 900 
    group: 900 
    type: "file" 
    writable: true 
    readable: true 
    executable: false 
    file: true 
    dir: false 
    link: false 
} 

,如果我嘗試 「的print_r()」,然後我得到,

Illuminate\Http\UploadedFile Object 
(
    [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => Brackpoints.png 
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/png 
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 148276 
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0 
[pathName:SplFileInfo:private] => /tmp/phpMhUyh0 
[fileName:SplFileInfo:private] => phpMhUyh0 
) 

    Symfony\Component\HttpFoundation\File\File Object 
    (
     [pathName:SplFileInfo:private] => ../public/images/phpMhUyh0 
     [fileName:SplFileInfo:private] => phpMhUyh0 
) 

在這裏,我想要得到的名稱和圖像的類型。 ..

我怎麼能得到?

回答

1

試試這個

echo $up->originalName; 
2
$up->getClientOriginalName(); 

$up->getMimeType(); 
+0

我得到的錯誤,當我使用$向上> getClientOriginalName(); ......................... 致命錯誤:調用未定義的方法Symfony \ Component \ HttpFoundation \ File \ File :: getClientOriginalName() ........................... 但$ up-> getMimeType();返回它的Mime類型。 –

+0

爲什麼你的對象改變了?它是'Symfony \ Component \ HttpFoundation \ File \ UploadedFile',現在它的'Symfony \ Component \ HttpFoundation \ File \ File'沒有辦法從第二種類型獲取原始名稱。 – Xiven

+0

'File \ File'我的文件已經移動了,所以你必須在此之前得到原始名稱。 – Xiven