2012-07-18, 03:27 AM
Okay You Must Know how to make Nav Bar Or Just a simple Few Modifications to the code to your own personalized liking : the code Will Be Displayed in a complex Tutorial Down Below Along With an Attachment With Example Files:
Creating the Form
HTML:To allow users to upload files from a form can be very useful.
Script: Create File Name it upload_file.php And Here is the code
It sets Restrictions To What kinda Files The user may upload ...So The user does not upload Viruses etc.
-------------------------------------------
The PHP Code Above is only to create a temporary copy of the uploaded files in the PHP temp folder on the server.
The temporary copied files disappears when the script ends. To store the uploaded file we need to copy it to a different location:
-----------------------------------------------------------------
This code Also Checks If the file already exists In the Directory "Upload" Or the directory you choose the files to be uploaded to:
Note 2Optional) In the example Folder They Must be Uploaded to an example site to work Or YOU WILL GET The following Error --
Creating the Form
HTML:To allow users to upload files from a form can be very useful.
<html>
<body>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
Create The Upload ScriptScript: Create File Name it upload_file.php And Here is the code
<?php
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
&& in_array($extension, $allowedExts))
{
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";
}
?>
This is the code For the UploadIt sets Restrictions To What kinda Files The user may upload ...So The user does not upload Viruses etc.
-------------------------------------------
The PHP Code Above is only to create a temporary copy of the uploaded files in the PHP temp folder on the server.
The temporary copied files disappears when the script ends. To store the uploaded file we need to copy it to a different location:
-----------------------------------------------------------------
This code Also Checks If the file already exists In the Directory "Upload" Or the directory you choose the files to be uploaded to:
<?php
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
+If you Want to Change the directory where the files will be stored Then Change the directory here("upload/"
Note: This example saves the file to a new folder called "upload" in the servers directoryQuote:Only The following Formats Are allowed to be uploaded jpg", "jpeg", "gif", "png"------------------------------------------------------
Note 2Optional) In the example Folder They Must be Uploaded to an example site to work Or YOU WILL GET The following Error --
Quote:0) { echo "Return Code: " . $_FILES["file"]["error"] . "Thanks :
"; } else { echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?>