Search code examples
phpapache

Error code 7 when I'm uploading file to my apache server


header("Content-Type:text/html; charset=utf-8");

if ($_FILES['test']['error'] === UPLOAD_ERR_OK){
  echo 'filename: ' . $_FILES['test']['name'] . '<br/>';

  if (file_exists('upload/' . $_FILES['test']['name']))
  {
    echo 'file exist<br/>';
  } 
  else 
  {
    $file = $_FILES['test']['tmp_name'];
    $dest = 'upload/' . $_FILES['test']['name'];

    move_uploaded_file($file, $dest);
    echo "seccess";
  }
} 
else 
{
  echo 'error code:' . $_FILES['test']['error'] . '<br/>';
}

This is my PHP code, I'm just trying to upload a simple tiny txt file to my apache server. It worked when I ran it in localhost, but error code 7 when I tried to run with apache.

chmod -R www-data:www-data /var/www

Already set www-data as the owner of www, disk space is enough to save the file.

Anything I can do to solve error code 7 problem?


Solution

  • Please check the directory has writeable permission. The error says that you don't have permission to save or write in that directory. Also, check disk space of that directory.

    For more details of error code, please see this link: http://php.net/manual/en/features.file-upload.errors.php