Attachments
Posted: Mon Jan 25, 2010 3:37 am
I have the following code on the page i want the attachments to be...
The table works fine and allows me to 'chose a file' and submit it...
This code is suppose to re-direct the upload into the folder 'upload' from 'temp_file' (i think?), but after i upload something it never appears in the upload folder. Any ideas on where i am going wrong?
Also how can i show the files that have been attached on the page?
The table works fine and allows me to 'chose a file' and submit it...
Code: Select all
<table width=800 height=50% class='smooth'>
<tr><td class=smooth height=10%>Attachement(s)</td></tr>
<tr><td><?echo $_FILES["file"]["name"] ?></td></tr>
</table>
<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>Code: Select all
<?php
if ($_FILES["file"]["size"] < 2000000)
{
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";
}
?>