2014-09-24 87 views
1

當我嘗試將圖像文件上載到服務器時,它隨機出現錯誤,有時它可以正常工作,而不會出現同一文件的問題。使用laravel上傳文件時發生未知錯誤

Symfony \ Component \ HttpFoundation \ File \ Exception \ FileException 
The file "xxxxxx.jpg" was not uploaded due to an unknown error. 

這是我的代碼:

if (Input::hasFile('thumbnail_image')){ 
    // Upload Photo 
    $thumbnailImage = Input::file('thumbnail_image'); 
    $filename = 'thumbnail.'.Input::file('thumbnail_image')->getClientOriginalExtension(); 
    $destinationPath = 'training_product/article_id_'. $id .'/thumbnail_image'; 
    $databasePath = '/adidas/public/training_product/article_id_'. $id.'/thumbnail_image'; 
    $uploadFile = Input::file('thumbnail_image')->move($destinationPath, $filename); 
    $product->thumbnail_images_path = $databasePath.'/'.$filename; 
    $product->save(); 
} 
+1

您的laravel日誌文件是否包含任何有用的信息? – 2014-09-24 12:55:55

+1

laravel日誌只是返回未知錯誤在線 $ uploadFile = Input :: file('thumbnail_image') - > move($ destinationPath,$ filename); 我猜這個文件沒有上傳,但我不知道哪個設置是錯誤的,爲什麼有時會工作,有時並不工作 – 2014-09-24 13:57:50

+0

如果文件已經存在於目標位置,會發生什麼? – Gagan 2016-02-07 07:06:17

回答

0

什麼是你的目標文件夾的文件權限?嘗試將其更改爲777(假設你使用的是Linux服務器:sudo chmod -R 777 adidas/public/training_product

我稍微修改您的代碼和它的作品對我來說

```

if (Input::hasFile('thumbnail_image')){ 
     // Upload Photo 
     $product = new Product; 
     $thumbnailImage = Input::file('thumbnail_image'); 
     $ext = $thumbnailImage->guessExtension(); 
     $filename = 'thumbnail_'. time() . $ext; 
     $destinationPath = 'training_product/article_id_'. $id .'/thumbnail_image'; 
     $databasePath = '/adidas/public/training_product/article_id_'. $id.'/thumbnail_image/'; 
     $thumbnailImage->move($destinationPath, $filename); 
     $product->thumbnail_images_path = $databasePath . $filename; 
     $product->save(); 
    } 

``。 `

我已經改變了getClientOriginalExtension()guessExtension(),實例化一個新的$product,因爲我沒有看到你做的事情。還確保了文件夾的權限,讓我上傳文件。

希望它有幫助。

+0

我已將權限更改爲777,並且所有者/組都是正確的。 我已經改變了你的代碼。它在函數guess($ path)處得到錯誤 FileNotFoundException 文件「/ var/www/html/tmp/php1wJ9ca」不存在 – 2014-09-24 13:46:05

相關問題