Jump to content

[SOLVED] Replacing a Space with %20


jonoc33

Recommended Posts

Hi guys. I have a script that shows a list of uploaded files, with a button saying Delete.

 

<?PHP 

$folder = "../files/upload/"; 
$handle = opendir($folder); 

# Making an array containing the files in the current directory: 
while (false !== ($file = readdir($handle)))
{
    if ($file != '.' && $file != '..')
       $files[] = $file; 
} 
closedir($handle); 

#echo the files 
foreach ($files as $file) { 
    echo "-<a href=$folder$file><label title=file>$file</label></a>";
echo "    [<a href=filedelete.php?file=$file>Delete</a>]<br />";
} 
?>

 

Now something is very weird, because if you attempt to delete a file that has a space in it, it appears as eg:

 

filename: de_dust A.jpg

file comes out as: de_dust

 

I need some way to replace the space with that %20 thing that normally shows up in links if there is a space in it.

 

Much thanks,

Jono

Link to comment
https://forums.phpfreaks.com/topic/77279-solved-replacing-a-space-with-20/
Share on other sites

Didn't seem to work. I may have put it in the wrong place.

 

Although, I don't want it to get rid of the space, I need it to keep it there but to still be able to delete it off, if you know what I mean. eg:

 

Uploaded File: de_dust A.jpg

Changes to: de_dust%20A.jpg

 

The %20, which i've seen, acts as a space.

try

 

<?PHP 

$folder = "../files/upload/"; 
$handle = opendir($folder); 

# Making an array containing the files in the current directory: 
while (false !== ($file = readdir($handle)))
{
    if ($file != '.' && $file != '..')
       $files[] = $file; 
} 
closedir($handle); 

#echo the files 
foreach ($files as $file) { 
    echo "-<a href=$folder".urlencode($file)."><label title=file>$file</label></a>";
echo "    [<a href=filedelete.php?file=".urlencode($file).">Delete</a>]<br />";
} 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.