Jump to content

Making a variable stay set???


gsaldutti

Recommended Posts

I have a page that loads and declares a certain variable ($isfile) as being equal to "" (just to declare it).  Then there is a script further down on the page that might be initiated by the user and if it is, that script sets the $isfile variable equal to "yes".

 

Then there is another script for another part of the page that loads the entire page again, so it always sets that $isfile variable back to "".

 

However, once it is set to "yes", I would like it to stay set to "yes". 

 

How can I make that happen?

Link to comment
Share on other sites

In the script that resets the $isfile variable, check to see if the its already to set to yes before setting it to ""

 

if(isset($isfile) && $isfile != 'yes')
   $isfile = '';

 

Now the $isfile variable shouldn't overwritten if its set to 'yes'.

 

This will only apply to current page. If you want variables to span over multiple pages then use sessions as suggested.

 

 

Link to comment
Share on other sites

I think those suggestions will work, thanks guys.  But to answer the question of why I keep reloading the same page...

 

It's basically a page where users can upload 10 different images.  I want them to be able to do it all on the same page rather than have to upload image #1 and then go to another page to do image #2 and then to another page to do image #3 and so on.  So I have a bunch of forms that upload images and they all call the same action (i.e. the current page).

 

I'm open to ideas to do it differently but it seems like if I want them to be able to upload them all from the same page, then I will have to keep calling the same page, right?

 

I'm new to this so I very easily could be missing something obvious.

Link to comment
Share on other sites

if you name your file upload fields as an array in your form, eg

<input type="files[]" ... />

 

Then you should be able to use a foreach loop to loop through all the uploaded files

 

foreach($_FILE['files'] as $file)
{
     // process uploaded
     echo '<pre>'.print_r($file, true).'</pre>';
}

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.