Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

338
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!