0

I am creating an app which needs to upload files, specifically videos and I am using laravel to do server-side php.

I have a form on my view

{{ Form::open(array('route' => 'testuploads.store', 'files' => true, 'enctype' => 'multipart/form-data')) }}
<ul>
    <li>
        {{ Form::label('title', 'Title:') }}
        {{ Form::text('title') }}
    </li>

    <li>
        {{ Form::label('body', 'Body:') }}
        {{ Form::textarea('body') }}
    </li>

    <li>
        {{ Form::token() }}
        {{ Form::label('file', 'File:') }}
        {{ Form::file('file') }}
    </li>

    <li>
        {{ Form::submit('Submit', array('class' => 'btn btn-info')) }}
    </li>
</ul>
{{ Form::close() }}

A controller

public function store()
{
    $input = Input::all();

    $file = Input::file('file');
    $pubpath = public_path();
    $destinationPath = $pubpath.'/uploads/'.str_random(8);
    $filename = $file->getClientOriginalName();
    $extension = $file->getClientOriginalExtension();
    // $path = $file->getRealPath();
    $size = $file->getSize();
    $mime = $file->getMimeType();
    $uploadSuccess = Input::file('file')->move($destinationPath, $filename);

    $validation = Validator::make($input, Testupload::$rules);

    if ($validation->passes())
    {
        $this->testupload->create($input);
        return Redirect::route('testuploads.index');
    }

    return Redirect::route('testuploads.create')
        ->withInput()
        ->withErrors($validation)
        ->with('message', 'There were validation errors.');
}

The error I get is:

Symfony \ Component \ HttpFoundation \ File \ Exception \ FileException
Unable to create the "/www/test/public/uploads/xTzlVlxb" directory

I have tried to change the permissions to the upload directory too, but that didn't worked. Any help appreciated, thanks.

1
  • 1
    Is /www/test/public/uploads/ writable? Commented Feb 10, 2014 at 15:39

1 Answer 1

2

Try to create the folder first with this method:

 File::makeDirectory($destinationPath,  $mode = 0777, $recursive = false);

And then move your file into that folder. Also i recommend to first check if the folder is created succesfully with:

 File::exists($destinationPath);
Sign up to request clarification or add additional context in comments.

3 Comments

Hi MaHo, thanks for the quick reply. That didn't worked either, the error has changed to an ErrorException mkdir(): Permission denied
I see your own answer, that you renamed your folder. Are you sure that the first folder 'uploads' had the correct permissions? Because it sounds a little bit odd that it works with a different name..
I did changed the permissions originally and checked if there are the correct ones but didn't worked, and yes its odd. Anyway, its working now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.