Reputation: 11
Here is the code which I am using
<form action="index.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file"><br><br>
<input type="submit" value="submit" name="submit">
</form>
PHP code :
<?php
$name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
$location = "/var/www/tmp/";
if(move_uploaded_file($tmp_name, $location.$name)){
echo 'File uploaded successfully';
} else {
echo 'You should select a file to upload !!';
}
?>
I checked the permissions of the folder as well as checked the php.ini file but still always I am getting 'You should select a file to upload '
Can anybody please help me out on this issue ?
Thank you so much!
Upvotes: 0
Views: 236
Reputation: 1106
Your Location should be like this:
// document root will give you the server root then you can add any directory after that (in your case its tmp I guess)
$location = $_SERVER['DOCUMENT_ROOT'] . '/your_preferred_dir/'
note: when you mention your preferred location you will have to make sure that this location should exists otherwise it will cause error.
And not hardcoded as yours because it can change from server to server.
Hope this helps...
Upvotes: 0
Reputation: 411
Give the full path of your file here
$location = "var/www/tmp/";
I think it will work. If its ok then store your servername in a variable and pass there.
Upvotes: 1