1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <?php $is_upload = false; $msg = null; if (isset($_POST['submit'])) { if (($_FILES['upload_file']['type'] == 'image/jpeg') || ($_FILES['upload_file']['type'] == 'image/png') || ($_FILES['upload_file']['type'] == 'image/gif')) { $temp_file = $_FILES['upload_file']['tmp_name']; $img_path = 'uploads/' . $_FILES['upload_file']['name']; if (move_uploaded_file($temp_file, $img_path)) { $is_upload = true; $msg= "<br/>成功上传至:<b> ".$img_path."</b>"; } else { $msg = '上传出错!'; } } else { $msg = '文件类型不正确,请重新上传!'; } } ?>
<div id="upload_panel"> <ol>
<li> <h3>上传区</h3> <form enctype="multipart/form-data" method="post" onsubmit="return checkFile()"> <p>请选择要上传的图片:<p> <input class="input_file" type="file" name="upload_file"/> <input class="button" type="submit" name="submit" value="上传"/> </form> <div id="msg"> <?php if($msg != null){ echo "提示:".$msg; } ?> </div> <div id="img"> <?php if($is_upload){ echo '<img src="'.$img_path.'" width="250px" />'; } ?> </div> </li> </ol> </div>
|