2011-11-30 3 views
1

로컬 서버에 PHP 스크립트를 작성했습니다.이 파일에는 아무런 문제없이 작동하고 있던 file_put_contents을 사용하여 파일에 내용을 쓸 파일의 경로가 포함되어야합니다. localhost. 예 : C : \ Program File (xxx) \ Apache Software Foundation \ Apache2.2 \ htdocs \ writtencode \ writefile \루트 폴더의 경로에있는 공백을 처리하는 방법

에 공백이있는 경로로 구성된 파일을 웹 서버로 이동했습니다.

나는 그것이 오류를 팝업 해당 폴더의 파일을 temp_1.cfg하는 내용을 작성하는 폴더의 WriteFile을 열려고하면

경고 : file_put_contents를 (C : \ ProgramFile (XXX) \ ApacheSoftwareFoundation \ 아파치. 2 \ htdocs \ writtencode \ writefile \ temp_1.cgf) [function.file-put-contents] : 스트림을 열지 못했습니다 : C : \ Program Fil에 디렉토리가 없습니다 전자 (XXX) \ 아파치 소프트웨어 재단 \ Apache2.2 \ htdocs를 \ writtencode \의 WriteFile \

파일에 내용을 기록 할 때 제거하거나 경로에 공간의 문제를 해결하는 방법을 어떤 생각의 index.php file_put_contents을 사용 하시겠습니까?

답변

0

경로를 따옴표로 묶으려고 했습니까?

file_put_content(C:\ProgramFile(xxx)\ApacheSoftwareFoundation\Apache2.2\htdocs\writtencode\writefile\temp_1.cgf);

이된다 : 또한 그렇게 모든 백 슬래시를 이스케이프해야 할 수 있습니다

file_put_content('C:\\ProgramFile(xxx)\\ApacheSoftwareFoundation\\Apache2.2\\htdocs\\writtencode\\writefile\\temp_1.cgf');

+0

내가 인용 부호로 경로를 동봉하고 난에 공백을 포함 할 필요가 경로를 사용하여 공백을 가져 와서 올바른 파일에 씁니다. – 125369

+0

좋아요, 쉬운 수정을 위해'subst x : "C : \ Program File (xxx) \ Apache Software Foundation \ Apache2.2 \ htdocs \ ' 배치 파일 (예 : mapx.bat). 이 배치 파일을 실행하면 htdocs 폴더는 x 드라이브를 통해 액세스 할 수 있습니다 : 'file_put_content ('x : \ writtencode \ writefile \ temp_1.cgf'); –

5
$path ="C:\ProgramFile(xxx)\Apache Software Foundation\Apache2.2\htdocs\writtencode\writefile\temp_1.cgf"; 
file_put_contents($path = str_replace(' ', '\ ', $path)); 
관련 문제