0

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.

2
  • 1
    Does the folder that will house the folder you are creating have the proper write permissions? Commented Oct 18, 2015 at 16:45
  • How can I check and change permissions? Commented Oct 18, 2015 at 16:47

2 Answers 2

1

Create a new directory with 744 write permissions.

mkdir ($currentPath . '/newfolder/', 0744);

I hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

I've edited my answer with the update. The (.) period operator is used to combine strings, which is what you need. Sorry, php is not my first language.
0

I added a few statements.

<?php
$currentPath = $_GET['curPath'];
//different ways I have tested
mkdir($currentPath+'/newfolder/', 0744);
mkdir($currentPath+'/newfolder1', 0744);
mkdir("newfolder3", 0744);
mkdir($currentPath+'/newfolder/newfolder/', 0744);
mkdir($currentPath+'/newfolder1/newfolder1', 0744);
mkdir($currentPath+'newfolder/', 0744);
mkdir($currentPath+'newfolder2', 0744);
mkdir($currentPath+'/newfolder/newfolder4/', 0744);
mkdir($currentPath+'/newfolder1/newfolder4', 0744);
?>

The only line that works is

mkdir("newfolder3", 0744);

But I want to use it with the currentPath variable. Is there a way to check what's $currentPath is assigned with? In the script.js currentPath looks like this files/place

3 Comments

Have you tried to echo $currentPath? Your problem is probably that you aren't passing $_GET['curPath'] in your GET form method.
It says domain/createfolder.php?curPath=files The path is now files. Shouldn't it be /files? This one doesn't work either: mkdir('/' + $currentPath + '/newfolder/', 0744);
Actually none. It's just not working. My editor even says that this mkdir('/' + $currentPath + '/newfolder/', 0744); is not allowed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.