F-y-o-d-o-r
12/19/2017 - 12:37 PM

php - files download

php - files download

if (isset($_FILES)) {
    $dir = "w:/domains/homeworks/2017.12.13/Long_homework_1/";
    for ($i = 0; $i < count($_FILES['file']['tmp_name']); $i++) {
      if (strpos($_FILES['file']['name'][$i], 'jpg') !== false or strpos($_FILES['file']['name'][$i], 'gif') !== false or strpos($_FILES['file']['name'][$i], 'png') !== false) {
        if (copy($_FILES['file']['tmp_name'][$i], $dir . $_FILES['file']['name'][$i])) {
          $name = $_FILES['file']['name'][$i];
          foreach ($massData as $key => $val) {
            foreach ($val as $key2 => $val2) {
              if (mb_strtolower(strip_tags($val2)) == strstr("$name", ".", true)) {
                $massData[$key][] = "<img src=" . $name . "></img>";
                $massData[$key][] = date('d-m-Y H:i:s');
              }
            }
          }
          echo 'succes' . '<br>';
        }
      } else {
        echo 'error';
      }
    }
  }
  /****************2d option******************/
  if (isset($_FILES['userfile'])) {
  //__DIR__
  $dir = '/home/localhost/www/';//директория куда загружать фото
  for ($i = 0; $i < count($_FILES['userfile']['tmp_name']); $i++) {
    if (copy($_FILES['userfile']['tmp_name'][$i], $dir . $_FILES['userfile']['name'][$i])) {
      echo $_FILES['userfile']['name'][$i] . '<br>';
    } else {
      echo 'Файл(ы) ' . $_FILES['userfile']['name'][$i] . ' загрузить не удалось!<br>';
    }
  }
}