the error message does not look like related to png file type nor file size issue... it's better to show the code that causing the error in order for other to help you...
file permission laravel
hello i have followed my problem on flare for an easy help.
My problem is : The "" file does not exist or is not readable. if i want to upload an image or multiple images.
link flare: https://flareapp.io/share/17xDdK7b#F52
[SOLVED] because the images was a png and the size is 4.9 mo i have try with another image, that work. One know what is this problem of png upload with the store method ?
Hello @siangboon i have already shared the code in flare app to be view by the community for the code who is bugged. But i think flare have a good solution to review bugged code ? Tell me if i'm on the bad way :) .
this is the code of my bugged png images.
public function submitProduct(Request $request)
{
//Validation
$request->validate([
'title' => 'required|unique:products',
'subtitle' => 'required',
'category' => 'required',
'description' => 'required',
'price' => 'required',
'stock' => 'required',
'filename' => 'required|file|size:3000000',
'price_1' => !is_null($request->input('option_1')) ? 'required' : 'nullable',
'price_2' => !is_null($request->input('option_2')) ? 'required' : 'nullable',
'price_3' => !is_null($request->input('option_3')) ? 'required' : 'nullable',
]);
$product = Product::all()->count();
if ($product < 16) {
try {
$data = $request->all();
$product = new Product();
$product->title = $data['title'];
$product->slug = Str::slug($data['title'],'-');
$product->subtitle = $data['subtitle'];
$product->category = $data['category'];
$product->description = $data['description'];
$product->price = $data['price'];
$product->stock = $data['stock'];
$product->save();
} catch (Exception $exception){
return redirect()->route('admin.dashboard')->with(['error' => 'An error was occured on the product creation, retry or contact admin.']);
}
if ($request->file('filename')){
foreach ($request->file('filename') as $img){
$path = $img->store('image', 'public');
$image = new Image();
$image->path = $path;
$image->products_id = $product->id;
$image->save();
}
}
if ($data['option_1'] && $data['price_1']
&& $data['option_2'] && $data['price_2']
&& $data['option_3'] && $data['price_3']){
$option = new Option();
$option->option_1 = $data['option_1'];
$option->option_2 = $data['option_2'];
$option->option_3 = $data['option_3'];
$option->price_1 = $data['price_1'];
$option->price_2 = $data['price_2'];
$option->price_3 = $data['price_3'];
$option->product_id = $product->id;
$option->save();
} elseif ($data['option_1'] && $data['price_1']
&& $data['option_2'] && $data['price_2'] ){
$option = new Option();
$option->option_1 = $data['option_1'];
$option->option_2 = $data['option_2'];
$option->price_1 = $data['price_1'];
$option->price_2 = $data['price_2'];
$option->product_id = $product->id;
$option->save();
} elseif ($data['option_1'] && $data['price_1']){
$option = new Option();
$option->option_1 = $data['option_1'];
$option->price_1 = $data['price_1'];
$option->product_id = $product->id;
$option->save();
} else {
return redirect()->route('admin.dashboard')->with(['error' => 'An error as been declared, i can\'t continue, contact admin']);
}
} else {
return redirect()->route('admin.dashboard')->with(['error' => "You've reached products limits creation, delete a product or upgrade your plan."]);
}
return redirect()->route('admin.dashboard')->with(['message' => 'Your product has been save with success.']);
}
do you include the enctype="multipart/form-data" in your form?
Yes i did it enctype, the name look like this name='filename[]' this is why i use the foreach to get all of images the user want to upload but the image go in another table than the users table. that make no sense to have many column for multiple image.
Please or to participate in this conversation.