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?
If you go to the PHP manual page, instead of W3schools (sometimes not really a good resources), you would see that your error code 1 is:
UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
That means your INI directive restricts your file upload (by default it should be 2Mbyte)
I know your is just a stub, but I suggest you doing chekcs on the kind of uploaded files, but especially actually DO UPLOAD the file (not just having it stored and then destroyed in the temporary directory) by using move_uploaded_file()
Your image file is too big according to your error code.