Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

me10071990's avatar

unable to create a temporary file in Unknown on line 0

When I try to upload a file from the Admin panel (in laravel).

In the apache log on server, I'm seeing message below.

Warning: Unknown: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/var/www/) in Unknown on line 0, referer: https://newworld/admin/letter

Warning: File upload error - unable to create a temporary file in Unknown on line 0, referer: https://newworld/admin/letter

What I do now here?

0 likes
21 replies
Snapey's avatar

You are trying to save a file outside of your hosting space.

Show your code so we can see where you are trying to save the file to?

1 like
me10071990's avatar

Yes, I am trying to save a file outside of my hosting space.

It was working fine, even I have uploaded multiple files before. However, recently some changes has been made by security team on server and from that time I have an error.

And here is my code

$data = [

        'title'=>$request->title,
        'category_id'=>$request->category_id,
        'slug'=>str_slug($request->title),
        'start_time'=>Carbon::parse(strtotime($request->start_time))->format('Y-m-d'),

    ];

    if (request('file')) {
        $file = request('file');
        $file_name = time() . $file->getClientOriginalName();
        $file->move('uploads/Letter', $file_name);
        $data['file'] = 'uploads/Letter/'.$file_name;
    }

Thank you @snapey .

jlrdw's avatar

You may have to put images under public_HTML if that is the case. Are you allowed to store images at least one folder above public_HTML. Also what host are you using.

You may want to start a ticket and find out exactly what is and what is not allowed.

Or even consider moving to something like digitalocean. Just a thought.

me10071990's avatar

@jlrdw thank you, it's simple hosting or can say private by organization. and what means of images under public_HTML.

jlrdw's avatar

Meaning whatever your public folder is. Give me a minute I'm on tablet I will post another link for you to look at I have to boot up my desktop.

jlrdw's avatar

See https://laracasts.com/discuss/channels/laravel/next-issue-fonts-and-images-arent-visible

I don't know your folder structure but in this image main larave is above public_html and public is now inside public_html called laravel54. (public can be renamed, I did).

Also public_html on some host have other names, like www, htdocs, etc.

You may want to show your folder structure for us to help.

Just create an account on imgur.com, upload screenshot, and view image, and place here in an image tag:

Like

<img src="https://i.imgur.com/Oo6k4Fp.jpg" />

Edit: Have you tried to move (store) image under your storage folder.

1 like
me10071990's avatar

I will ask to server manager to send the screenshot of server file images so it will help me more. And I will update here.

Thank you @jlrdw

Snapey's avatar

Thats some complex setup.

I hope your .env file is not available to download.

Anyway, as tmp is also used to hold the actual upload before you move it, comment out your code that actually saves the file and make sure you can upload without errors (not actually moving the file)

me10071990's avatar

Yes @snapey , thank you.

In .env file is not available to download.

Yes file are not moving.

so where I have to make changes in controler?

Snapey's avatar

Yes file are not moving.

Sorry I don't know what you mean. Do you get an error if you don't try to save the file?

Snapey's avatar

show us config/filesystems.php

Please format your code by putting 3 backticks ``` on a line before and after each code block

me10071990's avatar

No if I am editing the text then there are no error and sorry , my means file are not moving means , not saving on data base.

Thanks @snapey

Snapey's avatar

I don't think you understood what I was asking.

I'll try again.

Do this to your code;

    if (request('file')) {
//        $file = request('file');
//        $file_name = time() . $file->getClientOriginalName();
//        $file->move('uploads/Letter', $file_name);
//        $data['file'] = 'uploads/Letter/'.$file_name;
    }

NOW upload a file. Do you still get the error?

1 like
jlrdw's avatar
jlrdw
Best Answer
Level 75

@me10071990 somewhere run this

echo sys_get_temp_dir();
die;

EDIT: also check

echo ini_get('upload_tmp_dir');  // probably this one
die;

It will give you the tmp folder.

Then make sure that tmp folder has correct permissions:

chmod -R 777 /your/tmp/folder

And also make sure the folder you move to has correct permissions. But I don't think that's the problem.

But you said it worked until some security changes took place, ask someone,

What they did.

1 like
Snapey's avatar

so the problem is with your hosting setup, not your application.

Your web server account cannot read/write php's tmp folder

1 like
me10071990's avatar

@m7vm7v @snapey @jlrdw, thank you all, it works , the security check has been updated, so from outside I was not able to upload. Now working.

Thank you so much all.

1 like
jlrdw's avatar

Good to see you got it working.

2 likes

Please or to participate in this conversation.