blank space in a link that represents a path

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gulander
Forum Newbie
Posts: 1
Joined: Mon Nov 27, 2006 6:15 am

blank space in a link that represents a path

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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);
Post Reply