0

I am working on an intranet application that uses PHP and jQuery. When a user submits a form, the form is passed to another script via AJAX.

On one such form the user supplies a Windows UNC path to a server on the network. The handler script needs to create the directory the user specifies so that files can be moved via another process.

If I run a script from the web server using mkdir('\\server\path1\newpath') it works just fine. So I know the web server user has correct access rights.

But when I use the exact same command to the same network server in a script called via AJAX it fails with "No such file or directory".

Does the application lose its identity in an ajax call? Any ideas?

Thanks.

4
  • Are they both being run as the same user (so that they have the same permissions)? Commented Aug 19, 2010 at 15:30
  • Are the slashes in the path being interpreted as escape sequences?.. Commented Aug 19, 2010 at 15:32
  • If the script is actually mkdir('\server\path1\newpath') then the slashes shouldn't be interpreted as escape characters. single quote doesn't interpolate Commented Aug 19, 2010 at 15:50
  • Same user for both scripts. The slashes did not come out correctly when I made the post. I have used addslashes and did a str_replace to reverse the slashes. Both methods work on the standalone script, but not on the ajax called script. Commented Aug 19, 2010 at 16:19

3 Answers 3

1

Found the answer - one of those "oh!" moments. The user form field had a space at the beginning of it (it is populated from a database field). A simple trim fixed that issue.

Thanks for reading the question, and apologies for my aging eyes.

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

Comments

0

I had no idea backslashes can be this hard to deal with. Your choices are

  1. Make users enter an alternate directory seperator and use str_replace on the php side.
  2. Ask users to enter 2 backslashes and the directory seperator and then use escape when posting, when it reaches php it will be the correct seperator of one backslash.

    submitForm = function(path) { $.ajax({ type: 'POST', url: 'your_script.php', data: {path: escape(path)}, success: function() { } }); }

    submitForm('[2 backslashes]ugly[2 backslashes]windows[2 backslashes]path')

Not suprisingly the backslashes are preventing me from using the code formatting in the editor.

Comments

0

In Javascript you will need to escape the path value with encodeURIComponent(). On the PHP side you will need to decode it with rawurldecode(). This will eliminate backslash issues for sure.

Does the application lose its identity in an ajax call? Any ideas?

Under normal condition - no. It should preserve session. But if you manipulate cookies somehow - make sure you don't overwrite session id cookie.

Comments

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.