PHP实现上传文件到服务器

    技术2025-06-21  12

    <?php header('Content-type:text/html;charset=utf-8'); //var_dump($_FILES); if(isset($_POST['submit'])){//判断有没有post变量过来 if (is_uploaded_file($_FILES['myfile']['tmp_name'])) {//判断上传了没有 $arr=pathinfo($_FILES['myfile']['name']);//目的是为了找到扩展名 $newName=date('YmdGis').rand(1000, 99999); if(move_uploaded_file($_FILES['myfile']['tmp_name'], "uploads/{$newName}.{$arr['extension']}")){//移动并重命名 echo "上传成功!"; }else { echo "移动失败!"; } }else { exit('不正常呀!'); } //var_dump($_FILES); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="zh-CN"> <head> <title>上传页面</title> <meta charset="utf-8" /> </head> <body> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="myfile"/> <input type="submit" name="submit" value="开始上传" /> </form> </body> </html>

    Processed: 0.011, SQL: 9