我有一个基于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