Jump to content

$_GET from a URL?


LemonInflux

Recommended Posts

You probably know by now, I'm setting up an image uploader for a project, and want to add user interfaces. Well, everything's ok now, apart from delete. With help, I've come upon this code:

 

<?php
$files = array();
$dir=opendir($f_user);
while(($file = readdir($dir)) !== false)  
{  
if($file !== '.' && $file !== '..' && !is_dir($file))  
{  
	$files[] = $file;  
}  
}  
closedir($dir);
natcasesort($files);
echo "<ul>\n";
for($i=0; $i<count($files); $i++)  
{
if($files[$i] != "index.php")
echo "<li><a href=\"$dir/".$files[$i]."\">".$files[$i]."</a> - <a href=\"delete.php?del=$files[$i]\">Delete</a></li>\n";
}
echo "</ul>\n";
?>      

 

This code lists the directory contents and adds a 'delete' option next to the file. Upon pressing delete, it will send you to

http://reflexprojects.net/rs/upload/delete.php?del=yourfile.whatever

 

In delete.php, I have

 

<?php

$file = $_GET['del'];
$dir = "$f_user/$file"
if(unlink($dir)) {
echo "The file was deleted successfully.";
}
else {
echo "There was an error trying to delete the file.";
}

?>

 

Basically, this gets the file and tries to delete it. However, on this screen, I get nothing, just a blank white page. Not even the error echo works. So, here's my question: What's wrong with the second script?

 

If you would like to see what happens, log in at http://reflexprojects.net/rs/upload/secure_page.php?, with username and password as 'test'. Upload a picture, then try to delete it. Thanks in advance, Tom.

Link to comment
Share on other sites

  • Replies 103
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I would think it is supposed to be empty.

 

I think the unlink function might be causing some kind of problem. What if you do "echo $dir" right before the unlink line? See if something gets displayed, if not, comment out that entire if statement and see what it prints out for the $dir, it might be something weird.

Link to comment
Share on other sites

Are u sure u have a directory like: $dir = "$f_user/$file"? Normally if smth goes wrong an error should be printed, but maybe u have error_reporting off. If u have access to php.ini or a custom one try chaning error_reporting = e_all to see if u get any error.

Link to comment
Share on other sites

not sure if thi will help but i got this from php.net when i looked up opendir delete

 

<?php


recursive_delete($dir);

function recursive_delete( $dir )
{
        if (is_dir($dir)) {
           if ($dh = opendir($dir)) {
               while (($file = readdir($dh)) !== false ) {
                        if( $file != "." && $file != ".." )
                        {
                                if( is_dir( $dir . $file ) )
                                {
                                        echo "Entering Directory: $dir$file<br/>";
                                        recursive_delete( $dir . $file . "/" );
                                        echo "Removing Directory: $dir$file<br/><br/>";
                                        rmdir( $dir . $file );
                                }
                                else
                                {
                                        echo "Deleting file: $dir$file<br/>";
                                        unlink( $dir . $file );
                                }
                        }
               }
               closedir($dh);
           }
        }
}

?>

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.