Hi All

I'm trying to build a page that has a captcha and allows for a file upload.

Currently when I select a file, fill in the captcha and hit submit the file is uploaded to the server in a temp directory before checking the captcha. I need the captcha checked first before the file is uploaded.

Is there a way to spoof the browse box so that I can get the path for the file and use it on a secondary page that automatically uploads the file if the captcha is entered correctly and then takes the user to a confirmation page?

Any help would be greatly appreciated. :)

Recommended Answers

All 4 Replies

This is one of those dilemmas you have to code around.

Files uploaded to the tmp directory are usually deleted at the end of script execution. If you are wanting to remember the uploaded file for the next page load (like to show an error message) you are going to have to move the file from the tmp directory and move it to your own tmp directory. Pretty much a custom directory that won't delete files. You will need to run some code to keep it clean though.

Then when they finally fill out the form correctly you move the uploaded file to its final directory and delete the file in the custom temp folder.

Honestly this wasn't easy to get working properly, its going to take some time.

There might be js solutions, but I like this method rather and relying on javascript.

This is one of those dilemmas you have to code around.

Files uploaded to the tmp directory are usually deleted at the end of script execution. If you are wanting to remember the uploaded file for the next page load (like to show an error message) you are going to have to move the file from the tmp directory and move it to your own tmp directory. Pretty much a custom directory that won't delete files. You will need to run some code to keep it clean though.

Then when they finally fill out the form correctly you move the uploaded file to its final directory and delete the file in the custom temp folder.

Honestly this wasn't easy to get working properly, its going to take some time.

There might be js solutions, but I like this method rather and relying on javascript.

So what you're saying is that the file will upload first (to a tmp directory) regardless of anything else? And I won't be able to validate a captcha before the file is uploaded? :(

Not really, unless you try to use ajax.

Ok, thanks for the info ;) Guess I'm going to have to resort to a two stage process.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.