Page 1 of 1

form file

Posted: Sun Dec 11, 2011 10:50 pm
by kshitizgp
:?: the form code is

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="name">Name:</label><br />
<input type="text" name="name" value="" /><br />
<label form="email">Email:</label><br />
<input type="text" name="email" value="" /><br />
<label form="homework">Class notes:</label><br />

<input type="file" name="homework" value="Choose the file u want to upload" /><br />
<input type="submit" name="submit" value="Submit Homework" />
</form>


///
upload_file.php

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
}
else
{
echo "Invalid file";
}
?




am getting this error

Notice: Undefined index: file in C:\wamp\www\my_phpinfo\upload_file.php on line


??

Re: form file

Posted: Mon Dec 12, 2011 1:46 am
by Bind
in your php script, what you ahve as ["file"] needs to be the name value in your file upload form for the file, in this case ["homework"], or visa versa.

Re: form file

Posted: Mon Dec 12, 2011 3:05 am
by kshitizgp
can some1 give me an example ..... where i can create a user and passwords and access that in sesssion ....please am reading session examples but cant get a hang of it ....a simple example will do fine ? form + access using session ;)

Re: form file

Posted: Mon Dec 12, 2011 11:35 am
by social_experiment
Set your session variables:

Code: Select all

<?php
 // to use sessions you need to call this at the top of
 // your scripts
 session_start();

 // set a session variable
 $_SESSION['username'] = $_POST['name'];
?>
And on other pages will be:

Code: Select all

<?php
 session_start();

 // will contain whichever value was in $_POST['name']
 echo $_SESSION['username'];
?>
Passwords shouldn't be stored in sessions; unless they are vital to your script, but off hand i can't think of an example where that would be needed.

Re: form file

Posted: Mon Dec 12, 2011 9:04 pm
by kshitizgp
@ social experiment

Thnx alot :D muahh :P ..