当我尝试将图像文件上传到服务器时,随机出现错误,有时它可以正常工作,同一文件没有问题。
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();
}
答案 0 :(得分: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
,因为我没有看到你这样做。还要确保文件夹权限允许我上传文件。
希望它有所帮助。