pcw Posted April 28, 2009 Share Posted April 28, 2009 Hi, I am having a problem with deleting images. It worked a little while ago and cant think what I have done to change it. This lists and displays the images in the specified directory, but when I check the checkbox and click delete, instead of going to the specified delete.php script, it just lists the contents of the public_html directory. uploaded_files.php <?php session_start(); if($_SESSION['valid'] == true) { include_once("../common/header.php"); $username = $_GET['username']; print "<table width=700 border=0 align=center cellpadding=0 cellspacing=0>"; print "<tr>"; print "<td valign=top>"; print "<table width=700 border=0 cellpadding=0 cellspacing=0>"; print "<tr>"; print "<td>"; print "<table width=100% border=0 cellpadding=0 cellspacing=0>"; print "<tr>"; print "<td colspan=2>"; print "<h2 class=style2>Members Area<br /></h2>"; print "<hr />"; print "</td>"; print "</tr>"; print "<tr>"; print "<td class=style3>Your login has been successful</td>"; print "</tr>"; print "<tr>"; print "<td>"; print "</br>"; print "<table border=0>"; print "<tr>"; print "<td>"; print "<FORM>"; print "<input style='width: 188px;' style='background-color:#6495ED;' type='button' value='Upload Files' onclick=window.location.href='uploadform.php?&username=$username'>"; print "</td></tr>"; print "<tr><td>"; print "<input style='width: 188px;' style='background-color:#6495ED;' type='button' value='View Uploaded Files' onclick=window.location.href='uploaded_files.php?&username=$username'>"; print "</td></tr>"; print "<tr><td>"; print "<input style='width: 188px;' style='background-color:#6495ED;' type='button' value='Logout' onclick=window.location.href='logout.php?&username=$username'>"; print "</FORM>"; print "</td>"; print "</tr>"; print "</table>"; print "<br />"; print "</td>"; print "</tr>"; print "</table>"; print "</form>"; print "<br />"; print "<table width=300 border=1 cellpadding=0 cellspacing=0>"; print "<tr>"; print "<td>"; print "<table width=90% border=0 cellpadding=5 cellspacing=0>"; print "<tr>"; print "<td class=style3>Visit another secure page. </td>"; print "</tr>"; print "<tr>"; print "<td>"; print "<h2><a href=loggedin2.php>Go to page 2</a></h2>"; print "</td>"; print "</tr>"; print "</table>"; print "</td>"; print "</tr>"; print "</table>"; print "</td>"; print "<td>"; print "</br>"; print "</br>"; $path = "../../../../members/uploads/$username/"; $dir_handle = @opendir($path) or die("Unable to open folder"); while (false !== ($upload = readdir($dir_handle))) { if($upload == ".") continue; if($upload == "..") continue; print "<form action=delete.php?&username=$username method=POST>"; print "<table>"; print "<tr><td>"; print "<input type=checkbox name=upload value=../../../../members/uploads/$username/$upload>"; print "<img src='../../../../members/uploads/$username/$upload' alt='../../../../members/uploads/$username/$upload' height=100 width=100><br />"; print "<input type=submit name=delete value=Delete>"; print "</td></tr>"; print "</table>"; print "</form>"; } closedir($dir_handle); print "</td>"; print "</tr>"; print "</table>"; print "</body>"; print "</html>"; include_once("../common/footer.php"); } else { header("Location: ../../login.php"); } ?> delete.php <?php $username = $_GET['username']; if ($_POST["upload"]) { $myfile = $_POST['upload']; unlink($myfile); echo "File Deleted"; } else { echo "File Delete Unsuccessful"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/156012-solved-unlink-error/ Share on other sites More sharing options...
ignace Posted April 28, 2009 Share Posted April 28, 2009 You realize you have a serious whole in your application - about the size of 16 football fields? Try the following url: uploaded_files.php?username=../.. and see what it lists.. Quote Link to comment https://forums.phpfreaks.com/topic/156012-solved-unlink-error/#findComment-821297 Share on other sites More sharing options...
pcw Posted April 28, 2009 Author Share Posted April 28, 2009 Hi, thanks for your reply. That has the same result, obviously I dont want people to be able to view the entire contents of the public_html directory. What have I done wrong here? Quote Link to comment https://forums.phpfreaks.com/topic/156012-solved-unlink-error/#findComment-821303 Share on other sites More sharing options...
pcw Posted April 28, 2009 Author Share Posted April 28, 2009 I removed the username part of the action link to get the following: print "<form action=delete.php method=POST>"; it directs to the correct page delete.php and says the file has been deleted, but it doesnt delete the file. Any ideas on how to fix this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/156012-solved-unlink-error/#findComment-821380 Share on other sites More sharing options...
redarrow Posted April 28, 2009 Share Posted April 28, 2009 permission problems i guess, cmod 777 example <?php @chmod( $entry, 0777 ); @unlink( $entry ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/156012-solved-unlink-error/#findComment-821381 Share on other sites More sharing options...
pcw Posted April 28, 2009 Author Share Posted April 28, 2009 Thanks for your reply, but this didnt work. I have checked permissions are set to 0777 but no luck Quote Link to comment https://forums.phpfreaks.com/topic/156012-solved-unlink-error/#findComment-821392 Share on other sites More sharing options...
redarrow Posted April 28, 2009 Share Posted April 28, 2009 Are you sure, you got the correct path to the file? please look again, i think it should be the same directory, as the uploaded files i guess. Quote Link to comment https://forums.phpfreaks.com/topic/156012-solved-unlink-error/#findComment-821400 Share on other sites More sharing options...
pcw Posted April 28, 2009 Author Share Posted April 28, 2009 Hi, Yes the path to the file is correct, as I have the file displayed with img src before selecting it to delete. I cant put the script in the same directory as the uploaded files as the uploaded files are in a folder outside of the cgi-bin where the script is located. I cannot view uploaded files if they are stored within the cgi-bin. Quote Link to comment https://forums.phpfreaks.com/topic/156012-solved-unlink-error/#findComment-821404 Share on other sites More sharing options...
pcw Posted April 29, 2009 Author Share Posted April 29, 2009 Does anyone know how I can fix this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/156012-solved-unlink-error/#findComment-821661 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.