...

View Full Version : Passing Images Thorugh Multiple pages



elementis0
12-23-2007, 01:29 AM
Ok heres my problem,
I have an application form that users fill out online. part of this form deals with them having to upload images.
my problem is that I have 4 different pages the user goes through in the application process.

The users upload his picture on the first page,
What I want is for the pictures the user has uploaded in the form to only stay saved once they finish the application
I though a $_SESSION would keep the pictures safe until they were uploaded them on the last page, but i was wrong.

So what do I need to do to tell PHP to keep the images uploaded temporarily through multiple pages and not upload them into a permanent folder until the application process is finished?

basically all im looking for is something equivalent to a $_SESSION that can hold the actual image.

SeeIT Solutions
12-23-2007, 01:36 AM
You could save them to a temp folder and only move them somewhere to keep at the end of the process.

An image could be way too big to keep in session data, it would be much more effecient to store it in a temp folder and pass the filename around in a session variable.

Jesuspwnt
12-23-2007, 11:59 PM
then on the last page you could have the script delete the image =]
unset()

SeeIT Solutions
12-24-2007, 06:54 AM
unset() does variables. I think you mean unlink();

Jesuspwnt
12-24-2007, 10:14 AM
lol, yes i did mean unlink :P, sorry i wrote that post at like 2am so sorry for my errors :P

elementis0
12-24-2007, 08:12 PM
oh that makes perfect sense!
thank you.
but i have one question.
How would I go about making a temp folder?

SeeIT Solutions
12-25-2007, 01:38 AM
Put it at a level above your html directory (this way it can't be linked by the outside world). Just make a new folder like you would any other folder, call it temp.


root
public_ftp
public_html
index.php // site here
temp_uploads // uploads go here

something like that

elementis0
12-26-2007, 06:45 PM
ok i get that. but i mean how does the temp folder automatically delete the images if the application wasnt fully processed?

Inigoesdr
12-26-2007, 09:30 PM
It doesn't; you delete them with a cron job or at the start of the script using filemtime() (http://php.net/filemtime) or similar to make sure the file is old enough to not still be in use.

elementis0
12-27-2007, 02:41 AM
ok thank you.
except i dont think my setup does not support cron jobs.
how could i make a script that checks the folder and auto delete the files once a day just using php alone?
or is the a possible fix that emulates a cron job that can just delete my temp folder systematically?

muzammal
12-27-2007, 01:28 PM
I have also learned something new here

Inigoesdr
12-27-2007, 01:49 PM
how could i make a script that checks the folder and auto delete the files once a day just using php alone?
You would need to store the last time it was run in a database or text file, check for it on each pageload, and if it was last run more than a day ago execute the delete script. This is just an example of how you could delete the files; is not tested, but it should get you started:

$temp_folder = './temp/'; // with trailing slash
$d = dir($temp_folder);
while (false !== ($entry = $d->read()))
{
if($entry[0] != '.' && !is_dir($temp_folder . $entry) && filemtime($temp_folder . $entry) < (time() - (60 * 60 * 24))) // ignore directory pointers, directories, and files newer than a day old
{
unlink($tempfolder . $entry);
}
}
$d->close();

elementis0
12-27-2007, 08:20 PM
well i understand how to delete the files and all.
but what I really dont get is how to make the script auto-execute every day without using cron.

i think i may need a more thorough explanation of how to make it so it just autodeletes the files in the foler by checking the database or textfile.

I would just really like to thank you for all the help you have given me so far.

Inigoesdr
12-28-2007, 05:07 AM
$filename = 'last.txt';
$last = file_exists($filename) ? file_get_contents($filename) : 0;
$last = intval($last);

if(empty($last) || $last < time() - (60 * 60 * 24))
{
// delete files
$return = file_put_contents($filename, time());
}
You can add more error checking if you want.

elementis0
12-28-2007, 08:13 AM
thank you so much!
one last thing and then ill probably be sastisfied lol.

how do i make this script run by itself without have to actually manually execute it?
is that possible without crontabs?

Inigoesdr
12-28-2007, 11:10 AM
Place it at the bottom of your page so it is executed every time the page is loaded.

elementis0
12-28-2007, 08:29 PM
alright that sounds good. thanks for all your help!
now i got this thing working =D
and what i have coded for this app system so far is running smoothly ^_^



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum