Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查文件夹是否存在Ajax-php_Php_Jquery_Ajax - Fatal编程技术网

检查文件夹是否存在Ajax-php

检查文件夹是否存在Ajax-php,php,jquery,ajax,Php,Jquery,Ajax,我想检查键盘上目录\cms\sites\中是否存在名为$subdomaine的文件夹。 这是我的剧本: <script> $(document).ready(function(){ $('#subdomain').keyup(subdomain_check); }); function subdomain_check(){ var subdomain = $('#subdomain').val(); if(subdomain == "" || subdomain.length &

我想检查键盘上目录
\cms\sites\
中是否存在名为
$subdomaine
的文件夹。 这是我的剧本:

<script>
$(document).ready(function(){
$('#subdomain').keyup(subdomain_check);
}); 
function subdomain_check(){ 
var subdomain = $('#subdomain').val();
if(subdomain == "" || subdomain.length < 4){
$('#subdomain').css('border', '3px #CCC solid');
$('#tick').hide();
}else{
jQuery.ajax({
   type: "POST",
   url: "ajax.php",
   data: 'subdomain='+ subdomain,
   cache: false,
   success: function(response){
if(response == 1){
$('#subdomain').css('border', '3px #C33 solid');    
$('#tick').hide();
$('#cross').fadeIn();
}else{
$('#subdomain').css('border', '3px #090 solid');
$('#cross').hide();
$('#tick').fadeIn();
     }
 }
 });
 }
 }
</script>

$(文档).ready(函数(){
$(“#子域”).keyup(子域检查);
}); 
函数子域_check(){
var subdomain=$('#subdomain').val();
if(子域==“”| |子域.length<4){
$('#子域').css('border','3px#CCC solid');
$(“#勾选”).hide();
}否则{
jQuery.ajax({
类型:“POST”,
url:“ajax.php”,
数据:“子域=”+子域,
cache:false,
成功:功能(响应){
如果(响应==1){
$('#子域').css('border','3px#C33 solid');
$(“#勾选”).hide();
$('交叉').fadeIn();
}否则{
$('#子域').css('border','3px#090 solid');
$(“#交叉”).hide();
$('勾选').fadeIn();
}
}
});
}
}
ajax.php:

<?php 
$dirname = $_SESSION["subdomain"];
$filename = DOCUMENT_ROOT."sites/".$dirname;

if (!file_exists($filename)) {
   echo "The directory $dirname exists.";
    exit;
} 

试试这个,您需要使用
is_dir()
函数来检查给定的文件名is directory

if (is_dir($filename)) {
  echo "The directory $dirname exists.";
  exit;
} 
对于您的ajax响应

 if (is_dir($filename)) {
   echo 1;      
}else{
   echo 0;
}
更好的方法---

注意:将$\u会话也更改为$\u POST

<?php 
 $dirname = $_POST["subdomain"];  //look this
 $dir = DOCUMENT_ROOT."sites/".$dirname;

if(file_exists($dir) && is_dir($dir)){
   echo "The directory $dirname exists.";
   exit;
} 

?>

is_dir
您在javascript中使用了
if(response==1){
,因此您需要更改上面给出的php ajax响应文本谢谢您的帮助:)