accessing local file from php
I'm trying to gain access to a file on a client computer so that i can then later attach it to an outgoing email (resume.pdf)
Ive found a few clips of code but I'm having trouble getting it to work for me.
the code below seems to demonstrate all the things ill need to gather about my file but i can't quiet seem to get开发者_如何学编程 it to work yet.
does anyone have any idea what im doing wrong?
html code:
<input id="resumeup" name="resumeup" type="file"/>
php code:
$_FILES = $_POST["resumeup"];
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
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"];
}
}
For starters, don't overwrite $_FILES
with $_POST
; the former is created by parsing the multi-part form data in the request.
Second, make sure your form tag has said multi-part form encoding:
<form action="..." method="post" enctype="multipart/form-data">
The uploaded file will only be stored temporarily, you will need to use move_uploaded_file()
to relocate the file to a new location so that you can access it in the future.
You can read more on the PHP:
http://www.php.net/manual/en/features.file-upload.post-method.php
精彩评论