COUPDEGRACES's avatar

The requested resource file.pdf was not found on this server.

Hi, i have a problem with mycode, this case i want to Edit and update my image or file.pdf, but when im upload a pdf file or jpeg , i not see a error , but when im acces a file , i got notice like this

The requested resource file.pdf was not found on this server.

this is my Controller

    public function update(Request $request, $id)
    {
        $this->validate($request, [
            'content' => 'required',
        ]);

        $papan = Papan::findorfail($id);
        if($request->has('gambar')){
            $gambar=$request->gambar;
            $new_gambar=time().$gambar->getClientOriginalName();
            $gambar->move('public/uploads/papan/'.$new_gambar);
            $post_papan = [
                'content' => $request->content,
                'gambar' => 'public/uploads/papan/'.$new_gambar
            ];
        }
        else{
            $post_papan = [
                'content' => $request->content
            ];

        }
        $papan->update($post_papan);
        return redirect()->route('papan.index')->with('Berhasil', 'Pengumuman Berhasil Diperbarui');
    }
0 likes
26 replies
COUPDEGRACES's avatar

in this case , when im add , i can access my file , but when im try to edit and update, my file was not found in this server

siangboon's avatar

Double check your form again whether any.error, such as the path, method, or missing enctype="multipart/form-data"…

COUPDEGRACES's avatar

@siangboon im already add method patch sir , but still not found .

<form action="{{ route('papan.update', $papan->id) }}" method="POST" enctype="multipart/form-data">
    @csrf
    @method('patch')
<br>
automica's avatar

@hendrasaputra2323 ok.

What’s the url of where you are seeing the error?

Is the file being moved into /public/uploads/papal/ directory?

COUPDEGRACES's avatar

@automica in this case , when im add a file , i can acces my file , but when im edit and update , im cant acces my file again .

this code to show a file and pdf file

<td class="text-center"><a class="button w-24 mr-1 mb-2 bg-theme-7 text-white" href="{{ asset($hasil->gambar) }}" target="_blank"><strong>Show</strong></a></td>
                
automica's avatar

If you inspect the href using the inspector in your browser, what’s the url you get?

automica's avatar

Oh, and what version of laravel are you using?

COUPDEGRACES's avatar

@automica im using laravel 8 sir ,

and im already check my file in public/uploads/papan

and i see my file , but im confused , becasue my file not rename to Time.namefile.pdf but them automatically create new folder with name time.namefile.pdf

COUPDEGRACES's avatar

when im check using IE , im get url like this

http://127.0.0.1:8000/public/uploads/papan/1600374051lorem-ipsum.pdf
Snapey's avatar

how are you serving the site? You should not see public/ in your Urls

COUPDEGRACES's avatar

@automica my url root is 127.0.0.1:8000 .

im created a folder public in the folder public . so my file in url is 127.0.0.1:8000/public/uploads/papan/namefile.pdf

so i try change the folder , im rename to dokumen when i add a file , i can acces this file , and i have a same problem , when im edit and update a file , my file automatically change from file to folder .

and im got error like your file not found in this server ,

automica's avatar

In this line

        $gambar->move('public/uploads/papan/'.$new_gambar);

Change to

        $gambar->move('public/uploads/papan/');

You are specifying the full file path as the directory you are moving the file to.

COUPDEGRACES's avatar

i try this , when im acces the file , im going to

127.0.0.1:8000/dokumen/uploads/papan//tmp/php96oIG0
automica's avatar

Ah. So move() needs the full file name too.

Did you say your upload method works ok and it’s only the update one that doesn’t?

Can you post the upload method so I can compare?

COUPDEGRACES's avatar

of course sir , this my method uploads

    public function store(Request $request)
    {
        $this->validate($request, [
            'content' => 'required',
            'gambar' => 'required'
        ]);

            $gambar = $request->gambar;
            $new_gambar= time().$gambar->getClientOriginalName();

        $papan = Papan::create([
            'content' => $request->content,
            'gambar' => 'dokumen/uploads/papan/'.$new_gambar
        ]);

        $gambar->move('dokumen/uploads/papan', $new_gambar);
        return redirect()->route('papan.index')->with('Berhasil','Pengumuman telah diterbitkan');
    }

automica's avatar
automica
Best Answer
Level 54

Ah. This might be it

Change the line in your update to

    $gambar->move('public/uploads/papan', $new_gambar);

Looks like it could be you were using a period instead of a comma.

COUPDEGRACES's avatar

@automica Waaaaaaaaaaaaaah. I am very, very grateful, I have spent a few hours looking for the problem, you are a very extraordinary person, and I am very happy. Once again, thank you so much.

Your Awesoooooooooome !!

1 like
automica's avatar

@letmeknow glad we cracked it. Sorry it’s taken so many questions but I’m posting on my phone so it’s a bit harder to code dive,

COUPDEGRACES's avatar

@automica its okay sir , im using laptop can't to solve this problem -____- , once again thank you sir.

1 like

Please or to participate in this conversation.