Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

342
Visualizações
How to send $_FILES to $_SESSION variable properly?

I've recently started working on an Image Upload web application in PHP, and I plan on sending an $_FILES variable to another form, after being taken from a previous form.

For example: form1 has an <input type="file" name="image">. After that, form2 takes it using $_FILES['image'] and wants to send it to form3 via $_SESSION['image'] = $_FILES['image'].

The problem is, after I try to move_uploaded_file() using that session variable, the file isn't moved into the directory. My upload directory (in which I store all the images) is empty.

That's how I tried moving the file:

$file = "upload/".$link.".".pathinfo($_SESSION['file']['name'], PATHINFO_EXTENSION);
move_uploaded_file($_SESSION['file']['tmp_name'], $file);

Don't worry about $link. That's just some "key" I use in my links (a way to auto-generate the links).

I also tried declaring another $_FILES variable and assigning it the value of $_SESSION['file'], and then use it in move_uploaded_file(), but still didn't work.

My question is: is it possible to correctly pass a $_FILES variable to $_SESSION? If yes, how does it come that it doesn't work in my case. What did I do wrong?

If you need more code and (or) information, feel free to leave a comment and I'll provide it to you as soon as possible.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The problem is that the $_FILES array only points to the temporary location where the file is held. It does not contain the file data directly.

After your initial request ends, that temporary file is automatically removed. So while $_FILES may be persisted in the session, the actual file itself is not. You'll need to save it somewhere during the initial request (using move_uploaded_file()), and then put a reference to the saved file into the session, instead of the raw $_FILES data.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda