Sam San
Sam San

Reputation: 6903

use move_uploaded_file more than once

I call the move_uploaded_file on my code twice but seems that the second one doesn't work.

If I interchange the position of them,

then first one will works, but the second won't.

any suggestion?

Upvotes: 2

Views: 5088

Answers (4)

Mihai V
Mihai V

Reputation: 39

Form PHP manual: move_uploaded_file — Moves an uploaded file to a new location

If I understand right, what you probably do is that when you first call move_uploaded_file function you move the uploaded file into a new location, then when you call move_uploaded_file function the second time the function does nothing because the file is moved already.

Upvotes: 3

aleation
aleation

Reputation: 4844

Of course, when you moved the file once, it's not there anymore, it's like when you move a file from one folder to another in your computer.

On the second "move" you could use copy() to copy the file:

http://php.net/manual/es/function.copy.php

Upvotes: 1

MrCode
MrCode

Reputation: 64526

move_uploaded_file() as the name suggests, moves the temporary file. After it has been called, the temporary file no longer exists because it has moved.

From the Manual

If the file is valid, it will be moved to the filename given by destination.

Upvotes: 1

Rene Pot
Rene Pot

Reputation: 24815

You can't move a file twice. Perhaps you are looking for copy(). When you move the file, the original doesn't exists anymore.

Docs: http://php.net/copy

You could use move_uploaded_file and copy the file from there again

Upvotes: 6

Related Questions