이전에이 질문을 게시했지만 피드백을 사용하고 PHP 프로그램을 단순화하여 여전히 어떻게 실패했는지 보여줍니다. 여기에 을 내가 그 쓴 간단한 프로그램은 실패 보여줍니다 : 배열로 file_exists를 사용 는 항상 실패 이전 을 제안 배열에 php file_exists가 작동하지 않습니다.
[[email protected] steve]# ls -l data
total 4 -rw-r--r-- 1 root root 0 Sep 19 11:41 test_file
[[email protected] steve]# cat test_file.php
`#!/usr/bin/php -q
<?php
$i=1;
$testarray=array();
$testarray[$i]="test_file";
echo "testarray $testarray[$i]\n";
**if(file_exists("/home/steve/data/testarray[$i]")) {**
echo "file exists\n"; }
else { echo "file does not exist\n"; } `
[[email protected] steve]# php -q test_file.php
testarray test_file
file does not exist
[[email protected] steve]#
내가 디렉토리와 파일 이름 주위에 따옴표를 사용하고 아직 아니다 일.
의견을 보내 주셔서 감사합니다. 여기 누구나 시도 할 수있는 간단한 프로그램이 있으며 내가 얻고있는 것과 같은 결과를 얻을 수 있습니다. 모든/etc/hosts 파일에는 ip 127.0.0.1에 대한 "localhost"항목이 있습니다. IP에서 배열 그렙을 채우십시오. file_exists는 작동하지 않습니다. 그런 다음 하드 코딩하여 결과를 확인하십시오. 왜 같은 값을 반환하는 명령을 사용하여 배열을 poplulate하면 file_exists가 작동하지 않습니다. 각 과제에 대한 의견이있을 때마다 다음을 시도하십시오. – user1683269
#!/usr/bin/php -q php $ i = 1; $ hostname = array(); $ 호스트 이름 [$ i] ='grep 127.0.0.1/etc/hosts | awk '{print $ 3}''; # $ hostname [$ i] = "localhost"; "호스트 이름 [$ i] = $ 호스트 이름 [$ i] \ n"; if (file_exists ("/ home/steve/data/$ hostname [$ i]")) { echo "응용 프로그램 파일이 없습니다. \ n"; } else { echo "파일이 없습니다. \ n"; $ touch ='touch/home/steve/data/$ hostname [$ i]'; } ?> – user1683269