Jump to content

Recommended Posts

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");
} 

Link to comment
https://forums.phpfreaks.com/topic/203802-help-with-a-simple-upload-script/
Share on other sites

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

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?

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?

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).

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.

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.

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.