Home > Article > Backend Development > How to open php file php file operation
<pre name="code" class="php"><?php //文件上传 if(isset($_POST['submit'])){ //文件大小 $filesize=$_FILES['file']['size']; //文件名称 $name=$_FILES['file']['name']; //将文件名重新编码 $filename = iconv('utf-8','gbk',$name); //文件存放路径 $url='data/'; //判断源文件名称是否为空(判断是否已经选择上传的文件) if($filename!=""){ //判断该文件上传的错误代码数 if($_FILES['file']['error']>0){ echo"文件上传失败,请重试!"; }else{ /* *$_FILES['file']['tmp_name']文件上传后在服务器端存储的临时文件名 */ if(move_uploaded_file($_FILES['file']['tmp_name'],$url.$filename)) { echo $filesize; echo "文件上传成功!"; }else{ echo "文件上传失败,请重试!"; } } }else{ echo "请选择要上传的文件!"; } } //文件删除 if(isset($_POST['del'])){ //文件大小 $filesize=$_FILES['file2']['size']; //文件名称 $filename=$_FILES['file2']['name']; //文件存放路径 $url='data/'; $delfile=$url.$filename; //将路径重新编码 $delfile = iconv('utf-8','gbk',$delfile); //找寻文件 if (file_exists ($delfile)) { if(unlink($delfile)){ echo "删除成功"; } } } //文件名修改 if(isset($_POST['update'])){ //文件大小 $filesize=$_FILES['file3']['size']; //文件名称 $filename=$_FILES['file3']['name']; //文件存放路径 $url='data/'; $delfile=$url.$filename; //将路径重新编码 $delfile = iconv('utf-8','gbk',$delfile); //从表单获取新文件名 $newName=$_POST['newname']; $newfilename=$url.$newName; //从新编码 $newfileName=iconv('utf-8','gbk',$newfilename); if(rename($delfile,$newfileName)){ echo "修改成功!"; } } ?> <meta c/html"; charset="utf8" http-equiv="content-type"> <!--enxtype规定在提交表单时要使用那种内容类型--> <form action="" method="post" enctype="multipart/form-data"> <label>文件上传</label> <br/> <input type="file" name="file"> <input type="submit" name="submit" value="上传"> <br/> <label>文件删除</label> <br/> <input type="file" name="file2"> <input type="submit" name="del" value="删除"> <br/> <label>文件重命名</label> <br/> <input type="file" name="file3"> <label>更改的文件名:</label> <input type="text" name="newname"> <input type="submit" name="update" value="修改"> </form>
The above introduces how to open PHP files and PHP file operations, including how to open PHP files. I hope it will be helpful to friends who are interested in PHP tutorials.