Я довольно новичок в PHP, и я пытаюсь загрузить файл во вновь созданный каталог на моем ftp-сервере, например. новое имя каталога - это newDir, находящееся в корневом каталоге, я не слишком уверен, как работают пути в PHP, как мне это кодировать в PHP, но не загружать файл, это мой путь, я направляю его неправильно?Загрузка файла в каталог
<?php
if($_FILES){
//checking if a file is selected
if($_FILES['file']['name'] != ""){
//check if file is of type plain text file if not exit
if(isset($_FILES) && $_FILES['file']['type'] != 'text/plain') {
echo "<span> This is not an accepted file format, upload a .txt
document</span>";
exit();
}
echo "<center><span id='Content'> Contents of ".$_FILES['file']['name']."
File</span></center>";
//Getting and storing the temporary file name of the uploaded file
$fileName = $_FILES['file']['tmp_name'];
//echo "File has been uploaded and saved as" . "upload/" . $_FILES['file']
['name'];
//open file or display an error message if file cant open
$file=fopen($fileName,"r") or exit("Sorry unable to open the selected
file");
//reading the contents of the .txt document line by line
while(!feof($file)){
echo fgets($file) . " ";
}
// reading a .txt file character by character
while(!feof($file)){
echo fgetc($file);
}
fclose($file);
}
//check if user selects a file to upload
else
{
if(isset($_FILES) && $_FILES['file']['type'] == '')
echo "<span> Please choose a file by clicking on the 'Browse' or 'Choose
file' buttons. </span>";
}
}
//if the user clicks on the upload
//save the file to the new created directory on the server
if(isset($_POST['submit'])){
//upload file to the server
move_uploaded_file($_FILES['file']['tmp_name'], "upload/" . $_FILES['file']
['name']);
//create a variable message to hold the file name of the uploaded file
$msg = "New file ".$_FILES['file']['name']." has been uploaded to the server
<br />";}'
одна строка кода только не делайте вырез. Начните с руководств по загрузке и проверке ошибок. –
Что такое 'NewDir'? должен ли он быть var? или строку? – Jeff
путь, который вам нужно указать здесь, относится к веб-корню. и вам нужно передать его как строку здесь: 'move_upload_file ($ _ FILES ['file'] ['tmp_name']," NewDir/". $ _ FILES ['file'] ['name'];' – Jeff