Home > Backend Development > PHP Tutorial > How to open php file php file operation

How to open php file php file operation

WBOY
Release: 2016-07-29 08:33:13
Original
1151 people have browsed it
<pre name="code" class="php"><?php
//文件上传

if(isset($_POST[&#39;submit&#39;])){
	//文件大小
	$filesize=$_FILES[&#39;file&#39;][&#39;size&#39;];
	//文件名称
	$name=$_FILES[&#39;file&#39;][&#39;name&#39;]; 
	//将文件名重新编码
	$filename = iconv(&#39;utf-8&#39;,&#39;gbk&#39;,$name); 
	//文件存放路径
	$url=&#39;data/&#39;;
	//判断源文件名称是否为空(判断是否已经选择上传的文件)
	if($filename!=""){

		//判断该文件上传的错误代码数
		if($_FILES[&#39;file&#39;][&#39;error&#39;]>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>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template