2015-01-14 1 views
0

wkhtmltopdf를 사용하는 경우 URL에 %20이 포함되어 있으면 이미지를 생성 할 수 없습니다.wkhtmltopdf - URL 공백

명령 줄을 통해 동일한 명령을 로컬에서 수행 할 때 문제가되지 않습니다.

일단 온라인이되면이 방법을 사용할 수 있습니까?

내 코드는 지금까지입니다 : 이것은 잘 작동

<?php 
$url = $_GET['url']; // Website URL to Create Image 
$name = $_GET['img']; // Output Image Name 
$command = "/usr/local/bin/wkhtmltoimage --no-images --crop-w 580"; 
$dir_img = "images/";  // Image files will be saved here 
$ex_cmd = "$command $url " . $dir_img . $name; 
$output = shell_exec($ex_cmd); 
?> 

URL에 %20가없는.

%20이 URL에 포함되도록을 가지고 있으므로이 기능을 제거하는 것이 불행히도 해결책이되지는 않습니다.

답변

2
당신은 당신의 인수를 탈출해야

가, 다른 사람이 당신의 코드에 큰 보안 구멍이 있습니다

$url = escapeshellarg($_GET['url']); // Website URL to Create Image 
$name = escapeshellarg($_GET['img']); // Output Image Name 
$command = "/usr/local/bin/wkhtmltoimage --no-images --crop-w 580"; 
$dir_img = "images/";  // Image files will be saved here 
$ex_cmd = "$command $url " . $dir_img . $name; 
$output = shell_exec($ex_cmd); 

이것은 당신은 또한 ./config/database.php를 예 $_GET['url']는 URL입니다 확인하고 안, 당신이 시작하는 데 그냥, $_GET['img']도 위생 처리되어야합니다.