💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 第六课 文件操作 > 最大上传尺寸,post ``` <pre class="calibre14">``` <span class="token1">ini_get</span><span class="token2">(</span><span class="token4">'post_max_size'</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//最大post8M</span> <span class="token1">ini_get</span><span class="token2">(</span><span class="token4">'upload_max_filesize'</span><span class="token2">)</span><span class="token6">//最大上传2M</span> <span class="token1">ini_get</span><span class="token2">(</span><span class="token4">'max_execution_time'</span><span class="token2">)</span> 执行时间<span class="token3">30</span> <span class="token1">ini_set</span><span class="token2">(</span><span class="token4">'max_execution_time'</span><span class="token2">,</span> <span class="token3">600</span><span class="token2">)</span> 设置<span class="token3">600</span>秒 <span class="token1">set_time_limit</span><span class="token2">(</span><span class="token3">20</span><span class="token2">)</span> 同上 <span class="token1">ini_set</span><span class="token2">(</span><span class="token4">'display_errors'</span><span class="token2">,</span> <span class="token3">1</span><span class="token2">)</span><span class="token2">;</span>显示错误 ``` ``` > 返回文件名,包含文件名和不含扩展名 ``` <pre class="calibre14">``` <span class="token1">basename</span><span class="token2">(</span>$path<span class="token2">,</span><span class="token4">".php"</span><span class="token2">)</span><span class="token2">;</span> <span class="token6">//1.php</span> <span class="token1">basename</span><span class="token2">(</span>$path<span class="token2">)</span> <span class="token3">1</span> ``` ``` > 返回路径 ``` <pre class="calibre14">``` C<span class="token2">:</span>\www\Codelobster1<span class="token2">.</span>php <span class="token1">dirname</span><span class="token2">(</span><span class="token1">dirname</span><span class="token2">(</span>__FILE__<span class="token2">)</span><span class="token2">)</span><span class="token2">;</span> 返回两层C<span class="token2">:</span>\www <span class="token1">dirname</span><span class="token2">(</span>__FILE__<span class="token2">)</span> 返回一层C<span class="token2">:</span>\ 定义子目录文件 获取父目录路径 <span class="token1">define</span><span class="token2">(</span><span class="token4">'IA_ROOT'</span><span class="token2">,</span> <span class="token1">str_replace</span><span class="token2">(</span><span class="token4">"\\"</span><span class="token2">,</span> <span class="token4">'/'</span><span class="token2">,</span> <span class="token1">dirname</span><span class="token2">(</span><span class="token1">dirname</span><span class="token2">(</span>__FILE__<span class="token2">)</span><span class="token2">)</span><span class="token2">)</span><span class="token2">)</span><span class="token2">;</span> ``` ``` > file 数组读取文件,一行 > http\_build\_query($arr) 数组转换成&连接 qq=1&ss=5 ``` <pre class="calibre14">``` ``` ``` > 上传 ``` <pre class="calibre16">``` <span class="token1">move_uploaded_file</span><span class="token2">(</span>$file<span class="token2">[</span><span class="token4">'tmp_name'</span><span class="token2">]</span><span class="token2">,</span> $filename<span class="token2">)</span> <span class="token1">is_uploaded_file</span><span class="token2">(</span>$filename<span class="token2">)</span><span class="token2">;</span> $_FILES<span class="token2">[</span><span class="token4">'userfile'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'name'</span><span class="token2">]</span>原文件名 $_FILES<span class="token2">[</span><span class="token4">'userfile'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'size'</span><span class="token2">]</span>上传大小 __FILE__ 当前文件路径和文件名 <span class="token1">copy</span><span class="token2">(</span>$file<span class="token2">,</span> $newfile<span class="token2">)</span><span class="token2">)</span> 复制文件 <span class="token1">unlink</span><span class="token2">(</span><span class="token4">'test.html'</span><span class="token2">)</span><span class="token2">;</span> 删除文件 <span class="token1">disk_free_space</span><span class="token2">(</span><span class="token4">'/'</span><span class="token2">)</span> 返回目录的可用空间 <span class="token1">file_exists</span><span class="token2">(</span>$filename<span class="token2">)</span> 文件目录是否存在 <span class="token1">file_get_contents</span><span class="token2">(</span><span class="token4">'http://www.example.com/'</span><span class="token2">)</span><span class="token2">;</span>读取文件 <span class="token1">file_get_contents</span><span class="token2">(</span>$file<span class="token2">)</span><span class="token2">;</span> 写入文件可覆盖 <span class="token1">file</span><span class="token2">(</span><span class="token4">'http://www.example.com/'</span><span class="token2">)</span><span class="token2">;</span> 读入数组 <span class="token1">fileatime</span><span class="token2">(</span>__FILE__<span class="token2">)</span> 上次访问时间 filemtime 修改时间 filesize文件大小 字节 filetype 文件类型 fifo,char,dir,block,link,file 和 unknown $f<span class="token">=</span> <span class="token1">fopen</span><span class="token2">(</span><span class="token4">"/home/rasmus/file.txt"</span><span class="token2">,</span> <span class="token4">"r"</span><span class="token2">)</span><span class="token2">;</span> r只读 r<span class="token">+</span>读写 w写入不存在创建之 w<span class="token">+</span>读写<span class="token2">,</span>不存在创建之 a写入文件末尾<span class="token2">,</span>不存在创建之 a<span class="token">+</span>读写 <span class="token1">fread</span><span class="token2">(</span>$f<span class="token2">,</span> filesize <span class="token2">(</span>$filename<span class="token2">)</span><span class="token2">)</span><span class="token2">;</span> 读取文件 <span class="token1">fwrite</span><span class="token2">(</span>$f<span class="token2">,</span> $txt<span class="token2">)</span>写入文件 <span class="token1">is_dir</span><span class="token2">(</span>$tmp<span class="token2">)</span>是否目录 is_file是否文件 <span class="token1">is_readable</span><span class="token2">(</span>$filename<span class="token2">)</span>是否可读 <span class="token1">is_uploaded_file</span><span class="token2">(</span>$_FILES<span class="token2">[</span><span class="token4">'userfile'</span><span class="token2">]</span><span class="token2">[</span><span class="token4">'tmp_name'</span><span class="token2">]</span><span class="token2">)</span>是否post上传 <span class="token1">is_writable</span><span class="token2">(</span>$filename<span class="token2">)</span> 是否可写 <span class="token1">rename</span><span class="token2">(</span>$old<span class="token2">,</span>$<span class="token5">new</span><span class="token2">)</span> 重命名 <span class="token1">rmdir</span><span class="token2">(</span><span class="token4">'examples'</span><span class="token2">)</span><span class="token2">;</span>删除目录 <span class="token1">tmpfile</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>创建临时文件 $f <span class="token">=</span> <span class="token1">tempnam</span><span class="token2">(</span><span class="token4">"/tmp"</span><span class="token2">,</span> <span class="token4">"001"</span><span class="token2">)</span><span class="token2">;</span>创建唯一文件 <span class="token3">001</span>开头 ``` ```