I have a file manager running on a Linux server based on jQuery. This code is contained in the file script.js. There is also a tiny index.php which includes the script.
I added a button to the index.php and implemented its listener to the script. By pressing this button I want the listener to call a php script (createfolder.php) which creates a new folder in the current path.
Here are the relevant codes of the different files.
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");
?>
If I click the button I receive my test alerts as well as the proper path but the new folder won't be created.
Where did I make a mistake? Thanks.