Uploading a file fails under WordPress
- by Ash
I'm using WordPress and I'm following W3's guide for uploading a file:
HTML code:
<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>
PHP code (upload_file.php):
<?php
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"];
}
?>
The HTML code is pasted in a PHP page template and the PHP file under the WP installation directory under www.
The problem is when I submit the file I get Error: 1.
If I remark the "if" part of the PHP code and leave the "else" part I get:
Upload: IMG_4258.JPG
Type:
Size: 0 Kb
Stored in:
So at least I know the PHP code is running.
But what's causing it to fail?
Is there a problem with the code or is WordPress meddling with the process?