我有一个基于jQuery的Linux服务器上运行的文件管理器。此代码包含在文件script.js中。
还有一个很小的index.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");
?>
如果单击该按钮,我会收到测试警报以及正确的路径,但是不会创建新文件夹。
我在哪里弄错了?谢谢。
参考方案
创建一个具有744写权限的新目录。
mkdir ($currentPath . '/newfolder/', 0744);
我希望这有帮助。
在提交时在表单操作中获取变量丢失 - javascript当表单由onchange事件提交时,它不会保留get变量view。任何想法为什么会发生这种情况?提交后,这是它进入的网址,index?month=February&year=2014<form action="index?view=list" class="pure-form pure-fo…
选择后显示输入元素 - javascript我有一个表格,其中取决于用户的选择,输入元素是否可见。实际上,用户正在以另一种形式设置已定义的合作伙伴类型,并且如果选中该元素,则允许在该类型的合作伙伴上可见的元素类型1将显示以下元素:<input type="text" id="partner" name="partner" class=&…
JavaScript将PHP中的字符串和整数传递给函数 - javascript我正在尝试将字符串和整数都传递到同一函数中,但是引号引起了问题。我发现错误出在echo $q->info部分,我必须在此代码上使用双引号。有人可以帮我写这个$q->info,但不能获得真正的价值吗?到目前为止,我的代码是<td><a href="javascript:add(<?php echo $q->i…
Telerik单选按钮所需的字段验证器 - javascript如何设置Telerik单选按钮所需的字段验证器?我想在按钮单击“ BtnSave”上设置必填字段验证器吗?请帮忙!<telerik:RadButton ID="radio_male" runat="server" ToggleType="Radio" AutoPostBack="fa…
如何从javascript函数为gridview文本框设置值 - javascript我有以下项目模板的GridView<ItemTemplate> <asp:TextBox ID="txtComments" runat="server" Text='<%# Bind("Comments") %>' </asp:TextBox&…