Question
PHP upload
Hello,
I am using Dreamweaver Mx 2004 to develop a PHP site. I am trying to
implement a file upload page but I have run into a problem. Users are
supposed to select a file from one page and this file is supposed to be
uploaded using another. This is a snippet from the page where the user
selects the file:
--------------------------------------------------------------------------------------------
<form action="upload.php" method="post" enctype="multipart/form-data"
name="form1">
<label for="file">Filename:</label>
<table width="200" border="1">
<tr>
<td width="133"><input name="filefld" type="file" id="filefld"></td>
<td width="51"> </td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit"></td>
<td> </td>
</tr>
</table>
</form>
---------------------------------------------------------------------------------------------
The contents of the upload.php file are as follows:
<?php
if $_FILES["file"]["type"] == "image/pjpeg")
{
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("photos/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"photos/" . $_FILES["file"]["name"]);
echo "Stored in: " . "photos/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
" http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
After selecting a .JPG file I click on the submit button and the upload.php
file loads but nothing happens (meaning that the selected file is not
downloaded). I have checked the php.ini file to ensure that all the
necessary setting are there and that the temp upload folder has the
necessary windows permissions but still no luck. Any help would be
appreciated.
Liam
I am using Dreamweaver Mx 2004 to develop a PHP site. I am trying to
implement a file upload page but I have run into a problem. Users are
supposed to select a file from one page and this file is supposed to be
uploaded using another. This is a snippet from the page where the user
selects the file:
--------------------------------------------------------------------------------------------
<form action="upload.php" method="post" enctype="multipart/form-data"
name="form1">
<label for="file">Filename:</label>
<table width="200" border="1">
<tr>
<td width="133"><input name="filefld" type="file" id="filefld"></td>
<td width="51"> </td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit"></td>
<td> </td>
</tr>
</table>
</form>
---------------------------------------------------------------------------------------------
The contents of the upload.php file are as follows:
<?php
if $_FILES["file"]["type"] == "image/pjpeg")
{
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("photos/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"photos/" . $_FILES["file"]["name"]);
echo "Stored in: " . "photos/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
" http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
After selecting a .JPG file I click on the submit button and the upload.php
file loads but nothing happens (meaning that the selected file is not
downloaded). I have checked the php.ini file to ensure that all the
necessary setting are there and that the temp upload folder has the
necessary windows permissions but still no luck. Any help would be
appreciated.
Liam