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
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.

Link to comment
Share on other sites

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 />";
} 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.