Page 1 of 1

blank space in a link that represents a path

Posted: Mon Nov 27, 2006 6:26 am
by gulander
Hello to everyone,
I would like to create a zp file using the function system. My problem is that the strings that designate path contain blank space which results in spliting my path in two parts and hence error. How can I form my string so that a blank space in it is interpreted as a part of the path.

Code: Select all

$filen="F:/user/Apache Group/Apache/htdocs/tmp/";
$file_name=$filen.$_POST["Path"];
$file_n[0]=$file_name.".dbf";
$file_n[1]=$file_name.".doc";
$file_n[2]=$file_name.".pdf";
$dowpf = $filen."download.zip";
$com = "F:/user/tool/arch/zip.exe ".$dowpf." " .$file_n[0]." ".$file_n[1]." ".$file_n[2];
system($com);
I get following error:
zip warning: name not matched: Group//Apache//htdocs//tmp/download.zip
zip warning: name not matched: F://user//Apache
zip warning: name not matched: Group//Apache//htdocs//tmp/ter.dbf
zip warning: name not matched: F://user//Apache
zip warning: name not matched: Group//Apache2//htdocs//tmp/ter.doc
zip warning: name not matched: F://user//Apache
zip warning: name not matched: Group//Apache//htdocs//tmp/ter.pdf
Obviously the blank space between Apache and Group results in splitting of my path. How can I get around of this problem?
Thank you

Posted: Mon Nov 27, 2006 11:03 am
by volka
The path has to be in quotes, like

Code: Select all

zip.exe "F:/user/Apache Group/Apache/htdocs/tmp/yadda.zip"
escapeshellarg() will prepare an argument for proper use in a system() call.
Via array_map you can apply this function to all elements of an array.

try

Code: Select all

$filen="F:/user/Apache Group/Apache/htdocs/tmp/";
$file_name=$filen.$_POST["Path"];

$args = array_map('escapeshellarg', array(
		$filen."download.zip",
		$file_name.".dbf",
		$file_name.".doc",
		$file_name.".pdf"
	));

$com = "F:/user/tool/arch/zip.exe " . join(' ', $args);
echo "<div>Debug: com=", $com, "</div>\n"; flush();
system($com);