J
J
JackShcherbakov2018-02-16 16:45:19
PHP
JackShcherbakov, 2018-02-16 16:45:19

Why can't I save the file from the form?

Hello!
Needed but doesn't work:

  1. Save form data in /asd folder

Implementation:
<?php 
print "Размер в байтах принятого файла. - " . $_FILES["userfile"]["size"] . "<br>";
print "MIME тип файла - " .$_FILES["userfile"]["type"] . "<br>";
print "Временное имя, с которым принятый файл был сохранен на сервере. - " .$_FILES["userfile"]["tmp_name"] . "<br>";

print "<hr>";
print "Возника ошибка номер " . $_FILES["userfile"]["error"] . "<br>";
$uploaddir = __DIR__.'/files';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){
  print "Загрузка была завершена успешно.";
}else{
  print "Произошел какой-то треш при загрузке файла";
}
?>

Why is the file not saved? This is what the page looks like after uploading the file:

The size in bytes of the received file. - 1329
MIME file type - text/html The
temporary name with which the received file was saved on the server. - C:\OpenServer\userdata\temp\phpDDAB.tmp
------------------------------- -------------------------------------------------- ------------------
Error number 0 occurred The
download was completed successfully.

For some reason the /files folder doesn't contain any files
. What's wrong? How to fix? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
leni_m, 2018-02-16
@JackShcherbakov

echo $uploadfile;
what outputs?

A
Anton, 2018-02-16
@Eridani

Instead
of $uploaddir = __DIR__.'/files';
This is
$uploaddir = $_SERVER['DOCUMENT_ROOT'].'/files'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question