简体   繁体   中英

File upload in php not working on remote server

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!

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM