- <?php
- if(emptyempty($_GET[submit])) {
- ?>
- <form enctype=“multipart/form-data” action=“<?php $_SERVER[‘PHP_SELF’]?>?submit=1” method=“post”>
- Upload small image: <input name=“filename” type=“file”>
- <input type=“submit” value=“Upload”>
- </form>
- <?php
- }else{
- $path=“uploadfile/”;
-
-
-
-
- if(!file_exists($path))
- {
-
- mkdir(“$path”, 0700);
- }
-
- $tp = array(“image/gif”,“image/pjpeg”,“image/jpeg”,“image/png”);
-
- if(!in_array($_FILES[“filename”][“type”],$tp))
- {
- echo “File Type is incorrect”;
- exit;
- }
- if($_FILES[“filename”][“name”])
- {
- $file1=$_FILES[“filename”][“name”];
-
-
- $file2 = $path.$file1;
- $flag=1;
- }
- if($flag) $result=move_uploaded_file($_FILES[“filename”][“tmp_name”],$file2);
-
- if($result)
- {
-
- echo “<script language=’javascript’>”;
- echo “alert(\”Upload Success!\”);”;
- echo “</script>”;
- ?>
- <form enctype=“multipart/form-data” action=“<?php $_SERVER[‘PHP_SELF’]?>?submit=1” method=“post”>
- Upload small image: <input name=“filename” type=“file”>
- <input type=“submit” value=“Upload”>
- </form>
- <?php
-
- $dirr = ‘uploadfile/’;
- $dir = opendir($dirr);
- echo ‘<h1>success!</h1><br>’;
- echo ‘File size:’ . $_FILES[‘file’][‘size’] . ‘byte‘ . ‘<Br>’;
- echo ‘File Path:’ . $dirr;
- echo ‘<hr with=“100%” />’ . ‘<p>’;
- echo $dirr . ‘–Listing:<ul>’;
- while($file = readdir($dir)){
- echo “<li>$file</li>”;
- }
- echo ‘</ul>’;
- closedir($dir);
-
- }
-
-
- }
-
- ?>
php 图片上传