gsaldutti Posted November 16, 2008 Share Posted November 16, 2008 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? Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 16, 2008 Share Posted November 16, 2008 Use a session variable. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 16, 2008 Share Posted November 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 16, 2008 Share Posted November 16, 2008 "....there is another script for another part of the page that loads the entire page again" I guess it depends by what he means by "loads the page again." Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 16, 2008 Share Posted November 16, 2008 I would be interested to know why you have your page reload itself. Doing that looks bad to the visitor, it takes extra time to do, and it uses bandwidth and server resources. Quote Link to comment Share on other sites More sharing options...
gsaldutti Posted November 16, 2008 Author Share Posted November 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 16, 2008 Share Posted November 16, 2008 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>'; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.