2014-12-01 1 views
0

이 명령을 디렉토리에있는 파일을 검색 및 우편 번호에 따라, 그것은PHP 쉘 실행

$command = "cd {$root}/files && mkdir -p {$identifier} && zip -jFS -0 {$root}{$zipname} 2491/'test&.txt'"; 
    exec($command); 

그러나 변수는 쉘이 실행 가능하지 않으므로 파일을 변경, 아래의 코드가

작동하지 않습니다 잘 작동 동적 명령을 생성
$container_name = "2491"; 
$files = Array ('0' => 'test&.txt' ,'1' => 'test5.txt','2' => 'test6.txt'); 
$files = " " . $container_name . "/'" . implode("' " . $container_name . "/'", $files) . "'"; 
$files = str_replace('$', '\$', $files); 
$command = "cd {$root}/files && mkdir -p {$identifier} && zip -jFS -0 {$root}{$zipname} {$files}"; 
exec($command); 

$ root, $ identifier, $ zipname이 (가) 문제를 일으키지 않아 문제가되는 것은 무엇입니까? 실행 전에 $ 명령에 대한

는 업데이트

위해서 var_dump :

string(128) "cd /var/www/files && mkdir -p zip--1 && zip -jFS -0 /var/www/files/zip--1/1002_22-06022-06022-_content.zip 2491/'test&.txt'" 

하는 나는

exec("cd /var/www/files && mkdir -p zip--1 && zip -jFS -0 /var/www/files/zip--1/1002_22-06022-06022-_content.zip 2491/'test&.txt'"); 

실행 완벽하게

오류 Reponse로 실행하면 :

우편 오류 : 할 일 없음! (/var/www/files/zip--1/1002_22-06022-06022-_content.zip)

+1

실행 후'$ command' 변수의 출력을 게시 할 수 있습니까? – preinheimer

+0

명령을 실행하기 전에 덤프하고 확인하십시오. 변수를 사용하지 않을 때와 완전히 동일합니까? – vaso123

+0

@preinheimer 점점 압축 오류 : 할 수있는 일이 없습니다! (/var/www/files/zip--1/1002_22-06022-06022-_content.zip)을 명령 실행 응답으로 사용하십시오. – arpitr

답변

0

으로 챈드하고 있던 파일 이름이 '&' 인 문제가 수정되어 명령을 위반했습니다. 그것을 얻으려면 [htmlspecialchars_decode]를 사용하여 파일 이름을 전달했습니다. 1