Ricardo Varanda
Ricardo Varanda

Reputation: 147

Laravel - moving file causing error

I am trying to copy a file from one directory to another as follows:

$files = File::allFiles($temp);
                            foreach ($files as $f)
                            {
                                $f->move($destination, File::name($f));
                            }

I am getting this error:

Call to undefined method Symfony\Component\Finder\SplFileInfo::move()

In the following line: $f->move($destination, File::name($f));

It seems like it does not detect $f as being of type file because every time I try and use any of its functions like getClientOriginalName()

I get an error.

I keep getting that error. It seems as its not registering $f as being a file..

Also another thing to keep in mind is that I don't know the name of the file thus why I get all of the files in the directory (only ever 1 at a time)

Upvotes: 0

Views: 1898

Answers (3)

Nay Zaw Oo
Nay Zaw Oo

Reputation: 511

Try:

$files = File::files($temp);
foreach ($files as $file)
{
    File::move($file, $destination . basename($file));
    // [or]
    // rename($file, $destination . basename($file));
}

Upvotes: 0

Arlind Hajredinaj
Arlind Hajredinaj

Reputation: 8519

Change this line of code:

$files = File::allFiles($temp);

to

$files = Input::file('files');

Upvotes: 0

Ricardo Varanda
Ricardo Varanda

Reputation: 13

Try this:

File::get($f)

Let me know what happens.

Upvotes: 0

Related Questions