开发者

JQuery AJAX-PHP mkdir() issue

开发者 https://www.devze.com 2023-03-09 22:00 出处:网络
I\'ve been trying to get a script to work that calls a PHP file into a jQuery script using AJAX. var dataString = \'Submit=Set\';

I've been trying to get a script to work that calls a PHP file into a jQuery script using AJAX.

var dataString = 'Submit=Set';
$.ajax({
   type: "POST",
   url: "./inc/php/file.php",
   dataType: "json",
   data: dataString,
   success: function(data) {
    $('.error').html(data.errormsg+' OK.');
   },
   error: function(data) {
    $('.error').html(data.errormsg+' OH NO.');
    }
});

and it's calling this bit of PHP

$blogstatus =array();
$blogstatus['errormsg'] = 'NOTHING';
if(isset($_POST['Submit'])){ 
$blogstatus['errormsg'] = 'FIRST';

if (file_exists('/files/subfolder/')){
    $blogstatus['errormsg'] = 'exists';
}else{
    $blogstatus['errormsg'] = 'YES';
    mkdir('.开发者_运维百科/files/subfolder/',0777);
}
echo json_encode($blogstatus);  

If i take the mkdir out everything runs fine and i can call errormsg. I've tried running the mkdir without the ajax call in a standard PHP script, and that worked. Everytime i put the mkdir into the script i get the errormsg variable as undefined and the script fails.

Im fairly new to using jquery so it maybe something simple im over looking. cheers for any heelp


Please make sure the following points are satisfied:

Make sure the parent folder has the permission for apache to run your command?

Also, remove the trailing slash from your command

mkdir('./files/subfolder/',0777);

to

mkdir('./files/subfolder',0777);
- it is good to supply the full path when it comes to linux commands. For ex:

mkdir('/var/www/html/someproject/somemodule/files/subfolder',0777);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号