Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping a script from reading all the way thru

Status
Not open for further replies.

smashing

Programmer
Joined
Oct 15, 2002
Messages
170
Location
US
Hi!
I have a form that I'm using for file uploads. You fill out your company name and browse for a file that is then uploaded onto the server. Since I've put in my script to only accept files from people who've filled out their company name, people who try to send very large files (that may take 15-20 minutes to load), and forgot to put in their company name, they'll get an error after the 15-20 minutes that they didn't fill out the company name, and have to start from scratch.
What I'm looking for here is basically something to stop the script from reading the file upload part (which is a regular browse button <input type=&quot;file&quot; in the form) unless the company name text field is filled in. I've tried putting the upload part last, or into an if else condition (i.e. if company name not empty only then upload else exit) but nothing seems to stop it from reading and trying to copy the uploaded files.
I guess I can do it with Javascript, but I wonder if server side would work.
 
Hi,

You will want to do something like this:

<?php

if (empty($company_name))
{
## link to previous page
## or just show the input field again
}
else
{
echo &quot;<form action=\&quot;your_action\&quot; method=\&quot;your_method\&quot;><input type=\&quot;file\&quot; name=\&quot;name\&quot;><input type=\&quot;submit\&quot;></form>&quot;;
}
?>

Hope this helps!

Nate

mainframe.gif

 
I've thought of that. But that would mean spliting up the request for information into 2 steps. I wonder if I can't have everything on one form?
 
PHP is interpreted before it is sent to the browser, it can't do anything after the user has recieved the page (unless you use some arcane thing like remote procedure calls, but that's more trouble than it's worth). Your best option would be to use javascript, it's simple enough (I would tell you how to do it, but I haven't touched Javascript in a while and I'd probably give you code that doesn't work, there are loads of tutorials for this scattered around though).
 
i am fairly new to php but i think it would work.. so what spyder said...

<?php

if (empty($company_name))
{
## link to previous page
## or just show the input field again
}
else
{
echo &quot;<form action=\&quot;your_action\&quot; method=\&quot;your_method\&quot;><input type=\&quot;file\&quot; name=\&quot;name\&quot;><input type=\&quot;submit\&quot;></form>&quot;;
}
?>


but... make that your main form... sence it will be their first time seeing the page.. the company info should be blank sence it wasnt passed a string.. so it will in turn show the form field... and when they goto submit the file to upload.... if they havent entered the company info then it will just return back to the form.. over and over and over again untill they fill it out.. once filled out it shoudl run smoothly.. i dunnoo if id use *empty or isset* though... -shrug.. hope it helps

in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top