I cannot upload file to localhost using PHP. I have created simple html form and php script. However I get these error messages.
\'import.html\'
<
It looks like you're using Windows.
I'd change the destination path from a relative to an absolute path if possible. For example:
move_uploaded_file($_FILES["import"]["tmp_name"],
"C:/upload/" . $_FILES["import"]["name"]);
Or try the path:
$_SERVER['DOCUMENT_ROOT'] . '/upload/' . $_FILES['import']['name']
Also try creating that C:\upload\ or C:\xampp\htdocs\upload\ directory first before trying to upload to it.
This is old, but for people who have this problem in the future, all I did for my localhost (wamp) is click the server icon, go to PHP, PHP Settings, and select File Uploads.
This worked for me.
Well, according to your localhost directories you can try this:
if (!file_exists("teecom/upload"))
{
mkdir("teecom/upload", 0777, true);
}
if (file_exists("teecom/upload/" . $_FILES["import"]["name"]))
{
echo $_FILES["import"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["import"]["tmp_name"],
"teecom/upload/" . $_FILES["import"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["import"]["name"];
}
Your file was clearly not uploaded to the temporary folder from which the move_uploaded_file
function is supposed to move it. There is plenty of reasons why that might happen the most frequent one being that you don't have write permissions to the temporary folder PHP is using.