Closed masabahmed closed 4 years ago
Share your code but it seems like you're trying to upload a file that isn't accessible or found as the error says.
Make sure you give absolute and correct path to the file, ex: storage_path('image.jpg')
and the file is stored under storage
dir.
public function store(Request $request) { //Validate Ad $this->validate($request, [ 'title' => 'required', 'image' => 'image|nullable|max:1999', 'pm_link' => 'required', 'content' => 'required', 'status' => 'required' ]);
//Handle File Upload
if($request->hasFile('image')){
//Get filename with the extension
$full_file_name = $request->file('image')->getClientOriginalName();
//Get filename only without extension
$file_name = pathinfo($full_file_name, PATHINFO_FILENAME);
//Get file extension
$file_extension = $request->file('image')->getClientOriginalExtension();
//Filename to store
$file_name_new = $file_name . '_' .time().'.'.$file_extension;
//Upload image
$path = $request->file('image')->storeAs('public/cover_images', $file_name_new);
}else{
$file_name_new = 'noimage.jpg';
}
//Create Ad
$ad = new Ad;
$ad->title = $request->input('title');
$ad->name = 'name-will';
$ad->image = $file_name_new;
$ad->pm_link = $request->input('pm_link');
$ad->content = $request->input('content');
$ad->status = $request->input('status');
$ad->user_id = auth()->user()->id;
$ad->save();
// dd($ad->image);
Telegram::sendMessage ([
'chat_id' => '-482323143',
'parse_mode' => 'HTML',
'text' => $ad->title
]);
$remoteImage = $ad->image;
$filename = 'ironman';
Telegram::sendPhoto ([
'chat_id' => '-482323143',
'photo' => InputFile::create($remoteImage, $filename),
'parse_mode' => 'HTML',
'caption' => '$ad->content'
]);
return redirect('/ads')->with('success', 'Ad Created');
}
this my code , i want to send all of the $ads components to the group via my telegram bot. is it possible?
i will wait for your response and i will be thankful if you can help me this is my first laravel project
You've quotes around your var '$ad->content'
which is invalid.
You've just given file name to the InputFile::create
, like mentioned earlier you need to give absolute path to the file. In this case, it looks like it would be public_path('cover_images/'.$ad->image)
.
Please read Laravel docs as this is off-topic and not related to the SDK.
ok sir thanks
one thing this is the path of my image
and this is my code i change it as you said but it not works and this error is showing
kindly tell me the correct path for my image
if someone can solve my problem i shall be thankful