irazasyed / telegram-bot-sdk

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
https://telegram-bot-sdk.com
BSD 3-Clause "New" or "Revised" License
3.03k stars 669 forks source link

Telegram\Bot\Exceptions\CouldNotUploadInputFile File: `images_1600068177.jpg` does not exist or is not readable! #790

Closed masabahmed closed 4 years ago

masabahmed commented 4 years ago

if someone can solve my problem i shall be thankful

masabahmed commented 4 years ago

image

irazasyed commented 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.

masabahmed commented 4 years ago

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');
}
masabahmed commented 4 years ago

this my code , i want to send all of the $ads components to the group via my telegram bot. is it possible?

masabahmed commented 4 years ago

i will wait for your response and i will be thankful if you can help me this is my first laravel project

irazasyed commented 4 years ago

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.

masabahmed commented 4 years ago

ok sir thanks

masabahmed commented 4 years ago

one thing this is the path of my image image

masabahmed commented 4 years ago

image and this is my code i change it as you said but it not works image and this error is showing

masabahmed commented 4 years ago

kindly tell me the correct path for my image