简体   繁体   中英

Not able to upload file to web server

When I change the target directory from (relative?) "bilder/" to (absolute?) "/var/www/html/test/bilder/" I'm not able to upload files anymore from my computer to the web server. Anyone know what the problem might be?

I get no error from:

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)){ 
   echo "Success!";
} 
else { 
   echo "Error!";
} 

There may be some below reasons, which occurs frequently :

  1. enctype should be included in form tag ie

     <form method='' name='' enctype='multipart/form-data'> 
  2. Target Path should be correct.

  3. Directory may not have proper permissions.
  4. Images size is more than default uploaded size.
//select folder name perfectly
 $path = "image/" . $_FILES["file"]["name"]; 
 $file_name = $_FILES["file"]["name"];
 move_uploaded_file($_FILES["file"]["tmp_name"],$path);

You've to change the mode of www directory recursively (ie command will apply to all subfiles and subfolders), this is done by the following command at terminal:

sudo chmod 777 -R /var/www

if the above method would not work try this:

sudo chmod 777 -R /var

also remove the "forward slash" from your absolute path "/var/www/html/test/bilder/", this should be like this /var/www/html/test/bilder

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