sac0o01 Posted June 3, 2010 Share Posted June 3, 2010 I have a script that allows logged in users to upload images. The script checks first to see that there is not more than 8 images already uploaded before proceeding. The problem is once a user deletes some images the "die" message still appears. I am thinking it is a sessions problem? I am very new to this so I am sure it is a silly problem here is an extract: //upload directory. $upload_dir = "/home2/freefor3/public_html/rotasig/sigs/"; //count number of files in directory $dir_path = $upload_dir; $count = count(glob($dir_path . "*")); if($count >= { //step 1 die ("<b>You are only allowed maximum 8 files. Delete some files before uploading or upgrade to a premium account</b>" ); } else { //step 2 //number of files to upload. $num_files = 1; //the file size in bytes. $size_bytes =778240; //778240 bytes = 760 KB. //Extensions you want files uploaded limited to. $limitedext = array(".gif",".jpg",".jpeg",".png"); } Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/ Share on other sites More sharing options...
dabaR Posted June 3, 2010 Share Posted June 3, 2010 At the time when the die() runs, are there more than 8 images in the directory you list on the top of the script? Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067398 Share on other sites More sharing options...
TOA Posted June 3, 2010 Share Posted June 3, 2010 I am thinking it is a sessions problem? What makes you think that? I see no sessions being used anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067404 Share on other sites More sharing options...
sac0o01 Posted June 3, 2010 Author Share Posted June 3, 2010 dabaR , no you can add images up until you reach 8. After that it returns the message. So I proceed to the edit.php and delete some images. Upon returning to the upload page I am met with the die message before even trying to upload anything. The reason I thought it was a sessons issue is users login and a session is started. This is just an excerpt of where I believe the problem to be. At the top of this page is the session start Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067412 Share on other sites More sharing options...
dabaR Posted June 3, 2010 Share Posted June 3, 2010 Oh, OK. Nothing seemingly wrong with this piece, as far as I can see. Can you post the whole file? You could attach it to a post. Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067417 Share on other sites More sharing options...
TOA Posted June 3, 2010 Share Posted June 3, 2010 dabaR , no you can add images up until you reach 8. After that it returns the message. So I proceed to the edit.php and delete some images. Upon returning to the upload page I am met with the die message before even trying to upload anything. The reason I thought it was a sessons issue is users login and a session is started. This is just an excerpt of where I believe the problem to be. At the top of this page is the session start Ok, it would be good to throw that up there too. What session vars are you using? More specifically, are you recording the message you want dispayed in a session variable or just when the die() executes? If it's only when the die executes, Id think it wasn't a session issue. Could you post all the code involved? Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067419 Share on other sites More sharing options...
TOA Posted June 3, 2010 Share Posted June 3, 2010 Can you post the whole file? You could attach it to a post. Beat me too it Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067421 Share on other sites More sharing options...
dabaR Posted June 3, 2010 Share Posted June 3, 2010 I always say it is better to beat someone to the punch than it would be if you beat them with a punch. I think I made that up! I have my own silly quote! Pretty sweet. Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067422 Share on other sites More sharing options...
sac0o01 Posted June 3, 2010 Author Share Posted June 3, 2010 Attached is the entire page. Go easy on me it is the first script I have ever written. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067427 Share on other sites More sharing options...
dabaR Posted June 4, 2010 Share Posted June 4, 2010 OK, so what you have here is what is called a postback page. A page that has the GET version, which returns the HTML form to the browser...and you have the POST version, which is used to process the submission of that form. I commonly put all code that is meant to execute only when processing the form inside a if('POST' == $_SERVER['REQUEST_METHOD']) { ... } block. I see people often use if (isset($_POST['whatever_the_name_of_the_button_is'])){ ... } like you did. Don't you want to only check whether there are 8 things when the user is trying to post a new file? Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067442 Share on other sites More sharing options...
sac0o01 Posted June 4, 2010 Author Share Posted June 4, 2010 Yes, that is the goal. Stop the user from uploading any additional images after 8 until they visit the edit.php page and delete some images. Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067444 Share on other sites More sharing options...
dabaR Posted June 4, 2010 Share Posted June 4, 2010 Stop the user from uploading any images after 8 Yes, that is the goal. Stop the user from uploading any additional images after 8 until they visit the edit.php page and delete some images. but not stop the user from even trying to upload the image, right? Upon returning to the upload page I am met with the die message before even trying to upload anything. The reason I ask, is because the code that checks for number of uploaded images is not inside a if($this_is_a_post). Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067454 Share on other sites More sharing options...
sac0o01 Posted June 4, 2010 Author Share Posted June 4, 2010 What ever is simplest. Is there a way that would be preferred? Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067457 Share on other sites More sharing options...
dabaR Posted June 4, 2010 Share Posted June 4, 2010 How many images are there now? Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067461 Share on other sites More sharing options...
sac0o01 Posted June 4, 2010 Author Share Posted June 4, 2010 Each user gets their own folder when their account is created. Most only have a few images since the script is just an image rotator and not an image host. But a few users have 25 or 30 images so my bandwidth is getting chewed up rather quickly. So I want to be able to stop the heavy users from uploading until they reduce there image count and then after that simply maintain the level at 8 or whatever number I decide. Am I allowed to post a link to the site here? It may help you better understand the whole picture. Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067463 Share on other sites More sharing options...
dabaR Posted June 4, 2010 Share Posted June 4, 2010 I think you should be able to post a link. I link to my site all the time with the signature. You say you get an error on a certain page. That means a certain user has too many pictures. I would like to know how many pictures that exact user has right now. Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067464 Share on other sites More sharing options...
sac0o01 Posted June 4, 2010 Author Share Posted June 4, 2010 The site is Rotasig.com Register a new account and try it out. Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067473 Share on other sites More sharing options...
sac0o01 Posted June 4, 2010 Author Share Posted June 4, 2010 Too simple...figured it out. Changed the if / else statements around. I changed it to if there are less than 8 images then upload and the else is the message for being over. (does that make any sense?) Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067486 Share on other sites More sharing options...
dabaR Posted June 4, 2010 Share Posted June 4, 2010 Not sure whether it makes sense, but all that matters is that it works. From what I was sensing is that there were 8 images exactly, and that was causing a problem with the $count >= 8 Good job figuring it out. Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067502 Share on other sites More sharing options...
sac0o01 Posted June 4, 2010 Author Share Posted June 4, 2010 Thank you for all your time Dabar, and the lesson on a better way to POST. Quote Link to comment https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/#findComment-1067595 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.