我有一個基於jQuery的Linux服務器上運行的文件管理器。該代碼包含在script.js文件中。 還有一個小小的index.php,其中包含腳本。使用Ajax從jQuery調用PHP腳本創建一個新文件夾
我在index.php中添加了一個按鈕,並將其偵聽器實現爲腳本。通過按下這個按鈕,我希望偵聽器調用一個php腳本(createfolder.php),它在當前路徑中創建一個新文件夾。
以下是不同文件的相關代碼。
的index.php
<body>
<div class="filemanager">
<div class="search">
<input type="search" placeholder="Find a file.." />
</div>
<button type="button" id="createFolder">create folder</button>
<div class="breadcrumbs"></div>
<ul class="data"></ul>
<div class="nothingfound">
<div class="nofiles"></div>
<span>No files here.</span>
</div>
</div>
<!-- Include our script files -->
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="assets/js/script.js"></script>
的script.js
$("button").click(function() {
//just a test to see if the listener and the variable works
alert('test1: currentPath= ' + currentPath);
function callCreateFolderPhp() {
//also just a test
alert('test2');
$.ajax({
url: "createfolder.php",
type: "GET",
data: "curPath=" + currentPath,
success: function(msg){
//more testing
alert("test3");
}
});
//another one
alert('test4');
}
callCreateFolderPhp();
//final test
alert('test5');
});
createfolder.php
<?php
$currentPath = $_GET['curPath'];
//different ways I have tested
mkdir($currentPath+'/newfolder/', 0700);
mkdir($currentPath+'/newfolder1', 0700);
mkdir("newfolder2");
?>
如果我點擊按鈕,我收到我的測試警報以及正確的路徑,但不會創建新的文件夾。
我在哪裏犯了一個錯誤?謝謝。
將存放您正在創建的文件夾的文件夾是否具有適當的寫入權限? – Jesse
如何檢查和更改權限? – Tzizel