• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

a few html questions...

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

ps2cho

Member
Joined
Oct 13, 2004
Hey guys,

ok rescently i have been learning some php and i created a very very simple php upload script. Now...the website that i made is all done layout wise and it took a lot of time (mostly trial and error). I have my upload script in the uploadfile.php and then i have the following:
<b><font size=3>File Upload</font><br></b><br>
<img src="pics/dl.gif">
Select a file to upload:<br>

<form action="uploadfile.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" size="45">
<br>
<br>
By Pressing Submit, you agree that this file is none of the following:<br>
<ul>
<li>Pornography
<li>Virus(s), Spyware, Adware or keyloggers.
<li>Illegal or copyrighed material
<li>You have been warned<br>
<input type="submit" value="Upload File">
</form>

But you see that takes it to the success page if the file is ok which is on a blank page. How can i make it so that it will stay in the same page so they dont get redirected away?

Obviously the easiest way would be an iframe...but i dont like all the scroll bars as it looks stupid. Is there any other way of doing this? Or even remove the scroll bars?

Thanks, ps2cho
 
Set the form action to the same php file as this uploadscript. Then check if there has been some POST action and if yes process the file. If not display your form or whatever you want.
 
klingens said:
Set the form action to the same php file as this uploadscript. Then check if there has been some POST action and if yes process the file. If not display your form or whatever you want.

isnt it already pointing to the script? im kinda confused...
 
What you would want to do is this,

PHP:
<?

if(count($_POST)>0) 
{//the form was posted 
  //do your processing here
  $notices[]='Thank you for uploading a file!';
}
?>
<?if(isset($notices)) { ?>
<?  foreach($notices as $notice) { ?>
         <p class="notice"><?=$notice?></p>
<?  } ?>
<?}?>
<b><font size=3>File Upload</font><br></b><br>
<img src="pics/dl.gif">
Select a file to upload:<br>

<form action="uploadfile.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" size="45">
<br>
<br>
By Pressing Submit, you agree that this file is none of the following:<br>
<ul>
<li>Pornography
<li>Virus(s), Spyware, Adware or keyloggers.
<li>Illegal or copyrighed material
<li>You have been warned<br>
<input type="submit" value="Upload File">
</form>

This would be for the file "uploadfile.php."
 
there are two parts for an upload script:
a php file which displays the html above, and the php file which processes the $_POST with the files uploaded. the idea is to put both parts in one php file which displays the html form (with echo ""; for example) and also processes the inputs it $_POST has data.
 
Actually, I would avoid using echo to display the HTML. Merely close the PHP tags using ?> and reopen them with <?php when you need to return to PHP is fine.

Also,m the <?= tag is short for "<?php echo" which makes it very easy to use variables in your html.

I,E,

PHP:
<p>Your IP is <?=$_SERVER['REMOTE_ADDR'];?></p>
 
echo is good....

...as long as you only have a single one. mixing php and html in the same file is evil, cause it leads to spaghetti code:
Code:
$str = get_file_contents ("mytemplated.html");
ReplaceTemplatesWithData ($str, $data);
echo $str;
 
If i want to do the same thing with a different page (my login page) how would i do that?

my login.php checks using the authenticate.php which displays "you have logged in" on a new page...how do i keep that on the login.php?

Login.php
PHP:
Please enter your user details to log-in here...<br>

 <form action = "authenticate.php" method = "post">
 Username:<br>
 <input type = "text" name = "username">
 <br><br>
 Password:<br>
 <input type = "text" name = "password">
 <br><br>
 <input type = "submit" value = "Log In">
 </form>
 
Merge the functionality of the authenitcate.php into the login.php. Use the same thought process we showed before.
PHP:
if(count($_POST)>0)
{

//authenticate code here

}
else
{
//login code here
}
 
Back