Reputation: 29
I have xampp installed and I have a program that you choose a file and it gets uploaded to my server. I have a folder in htdocs called uploads thats meant for storing the pictures. When I upload them, it goes in the htdocs, but not the folder in htdocs i want. I did specify that i needed it to go there. Can someone help?
Heres the code:
<?php
@$name = $_FILES['file']['name'];
@$size = $_FILES['file']['size'];
@$type = $_FILES['file']['type'];
@$tmp_name = $_FILES['file']['tmp_name'];
if (isset($name)) {
if (!empty($name))
{
$location = 'uploads/';
if (move_uploaded_file($tmp_name, $location. $name));
echo 'Uploaded';
}
else
{
echo 'Please choose a file';
}
}
?>
<form action="first.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="Submit" value="Submit">
</form>
Upvotes: 2
Views: 7969
Reputation: 177
Try below code:
Note: Make sure your uploads
folder have write permission.
<?php
define("DOC_ROOT", $_SERVER['DOCUMENT_ROOT']."/");
define("PDF_UPLOADS", DOC_ROOT."uploads/");
$name = $_FILES['file']['name'];
$size = $_FILES['file']['size'];
$type = $_FILES['file']['type'];
$tmp_name = $_FILES['file']['tmp_name'];
if (isset($name))
{
if (!empty($name))
{
if(move_uploaded_file($tmp_name, PDF_UPLOADS. $name))
echo 'Uploaded';
else
echo "Not Uploaded";
}
else
{
echo 'Please choose a file';
}
}
?>
Upvotes: 3