Posting & Upload

A

Anonymous

Guest
Hi,

To avoid posting when the user hits the page, you have to enclose the code into: if(isset($_POST['upload'])), upload being the name of the submit button (i would change the form name since it is the same than the submit button).
Besides, in the form tag, you have to specify an action, that tells the form what to do when submitting. The action usually is a js or a php file that processes your form info. The syntax is: <form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post" action="processform.php">. Based on your code, i'd use action="<?php echo $_SERVER['PHP_SELF'];?>", that means the form will be processed in the same page it is being generated.

Hope it helps.
 
Code:
<?php 

if(isset($_POST['upload'])){

// HERE GOES YOUR FORM PROCESSING. IT IS ENCLOSED IN THE if(isset()) SO AS TO BE EXECUTED ONLY WHEN COMING FROM A POST

}
?>



<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">

<td><input type="submit" name="upload" value="Upload & Post"></td>
</form>
 
If i have understood, you don't have to assign a new name when uploading a file. It automatically gets the name of the origin. Anyway, as far as i know, you can use any name you want (however think of the server you are uploading to, it might have problems with certain characters).

Regards.
 
Back
Top