建立資料夾功能
1,前端顯示建立按鈕
在netdisk_html.php頁面加入以下程式碼:
<?php <form method="post"> 新建文件夾:<input type="text" name="newfolder"> <input type="submit" value="創(chuàng)建"> </form>
可以在input框內(nèi)寫入需要建立的資料夾名稱然後點(diǎn)擊建立透過post方式提交
2,在index.php頁面取得
因?yàn)樵趇ndex.php文件引入了require('netdisk_html.php'),所以預(yù)設(shè)提交就是當(dāng)前頁面,不需要再寫action="index.php",當(dāng)然寫了也不會報(bào)錯(cuò)
獲取到post提交的資料對資料執(zhí)行新資料夾功能即可,具體程式碼如下:
<?php //獲取表單傳來的數(shù)據(jù) $newfolder=isset($_POST['newfolder'])?trim($_POST['newfolder']):""; //創(chuàng)建文件夾功能 if($newfolder==''){ // echo "創(chuàng)建文件夾失敗"; }else{ //不能建已經(jīng)存在的文件夾--進(jìn)行判斷 $sql="select folder_name from netdisk_folder where folder_pid=$folder_id AND folder_name='$newfolder'"; $allfolder=fetchRow($sql); if($allfolder){ echo "文件名不能重復(fù)"; }else{ //正常創(chuàng)建的情況下 $sql="insert into netdisk_folder (folder_name,folder_time,folder_path,folder_pid) values('$newfolder',now(),$folder_id,$folder_id)"; $result=query($sql); if($result){ // echo '添加成功'; }else{ echo '添加失敗'; } } }
3,頁面展示: