cffile
Управляет взаимодействием с файлами на сервере. Для разных комбинаций требуются разные атрибуты.
<cffile action="read">
fileRead(path);
Справочник по атрибутам
action string Обязательный
appendcopydeletemovereadreadbinaryrenameuploaduploadallwrite
file string
mode string
output string
addnewline boolean
По умолчанию: true
true
truefalse
attributes string
readonlyhiddennormalsystemtemporary
charset string
utf-8iso-8859-1windows-1252us-asciishift_jisiso-2022-jpeuc-jpeuc-krbig5euc-cnutf-16
source string
destination string
variable string
filefield string
nameconflict string
errorskipoverwritemakeunique
accept string
result variableName
По умолчанию: cffile
cffile
fixnewline string
По умолчанию: false
false
truefalse
cachedwithin numeric
Совместимость
BoxLang:
<bx:file> в BoxLang Ссылки дополнительная информация о cffile
- Советы по безопасной загрузке файлов с помощью CFML — запись в блоге Пита Фрайтага с рекомендациями по повышению безопасности при загрузке файлов в CFML.
Примеры Примеры кода с использованием тега cffile
Запись в файл
fileWrite(expandPath("./myFile.txt"), "Here's some content for my file."); Добавление в файл — поскольку функции fileAppend() нет, мы открываем файл и используем fileWriteLine()
myFile = fileOpen(expandPath("./myFile.txt"), "append");
fileWriteLine(myFile, "Here's some new content.");
fileClose(myFile); Чтение файла
myFile = fileRead(expandPath("./myFile.txt")); Чтение бинарных данных из файла
myImageBinary = fileReadBinary(expandPath("./myImage.jpg")); Переименование файла — поскольку функции fileRename() нет, fileMove() работает так же хорошо
fileMove(expandPath("./myFile.txt"), expandPath("./myNewFileName.txt")); Копирование файла
fileCopy(expandPath("./myFile.txt"), expandPath("./some/other/path")); Перемещение файла
fileMove(expandPath("./myFile.txt"), expandPath("./some/other/path")); Удаление файла
fileDelete(expandPath("./myFile.txt")); Загрузка файла
fileUpload(getTempDirectory(), "form.myFile", " ", "makeunique"); Загрузка всех файлов
fileUploadAll(getTempDirectory(), " ", "makeunique"); Запись содержимого переменной в файл.
<cffile action="write" file="#expandPath("./myFile.txt")#" output="Here's some content for my file."> Добавление содержимого в конец файла.
<cffile action="append" file="#expandPath("./myFile.txt")#" attributes="normal" output="Here's some new content."> Чтение файла в переменную
<cffile action="read" file="#expandPath("./myFile.txt")#" variable="myFile"> Чтение бинарных данных из файла
<cffile action="readBinary" file="#expandPath("./myImage.jpg")#" variable="myImageBinary"> Переименование файла
<cffile action="rename" source="#expandPath("./myFile.txt")#" destination="#expandPath("./myNewFileName.txt")#" attributes="normal"> Копирование файла
<cffile action="copy" source="#expandPath("./myFile.txt")#" destination="#expandPath("./some/other/path")#"> Перемещение файла
<cffile action="move" source="#expandPath("./myFile.txt")#" destination="#expandPath("./some/other/path")#"> Удаление файла
<cffile action="delete" file="#expandPath("./myFile.txt")#"> Загрузка файла, содержащегося в поле myFile. Всегда загружайте файлы в каталог за пределами корневого каталога веб-сервера, проверяйте расширение и содержимое файла и только затем, при необходимости, копируйте его обратно в корневой каталог веб-сервера.
<cffile action="upload" destination="#getTempDirectory()#" filefield="form.myFile" nameconflict="makeunique"> CF 10+ Проверяет расширения файлов по списку разрешённых расширений. При указании списка расширений файлов необходимо задать strict=false.
<cffile action="upload" accept=".png,.jpg" strict="false" destination="#getTempDirectory()#" filefield="form.myFile" nameconflict="makeunique"> Загрузка всех файлов из области формы.
<cffile action="uploadall" destination="#getTempDirectory()#" nameconflict="makeunique">
© 2012–present Foundeo, Inc. and the CFDocs contributors.
Licensed under the MIT License.
ColdFusion is a trademark of Adobe Systems Incorporated.
https://cfdocs.org/cffile