pcw Posted April 30, 2009 Share Posted April 30, 2009 Hi, I have the following script to delete uploaded files from a users account. However, images, videos and audio files are all stored in different folders and will not delete unless I have a different delete script for each one, as the directories are different. ie. $delUpload = "../../../../members/uploads/$username/image/"."$upload"; $delUpload = "../../../../members/uploads/$username/video/"."$upload"; $delUpload = "../../../../members/uploads/$username/audio/"."$upload"; I was wondering if it was possible to put in the script that if the delete.php file was accessed from the uploaded_images page, then use: $delUpload = "../../../../members/uploads/$username/image/"."$upload"; is this possible, and how would I go about implementing this? <?php session_start(); if(($_SESSION['valid'] == true) && ($_POST['upload'])) { include_once("../common/header.php"); $username = $_GET['username']; $upload = $_GET['upload']; 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 Audio' onclick=window.location.href='uploaded_audio.php?&username=$username'>"; print "</td></tr>"; print "<tr><td>"; print "<input style='width: 188px;' style='background-color:#6495ED;' type='button' value='View Uploaded Images' onclick=window.location.href='uploaded_images.php?&username=$username'>"; print "</td></tr>"; print "<tr><td>"; print "<input style='width: 188px;' style='background-color:#6495ED;' type='button' value='View Uploaded Videos' onclick=window.location.href='uploaded_videos.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>"; $delUpload = "../../../../members/uploads/$username/image/"."$upload"; unlink("$delUpload"); print "</br>"; print "<p class=style2>File Deleted</p>"; print "</td>"; print "</tr>"; print "</table>"; print "</body>"; print "</html>"; include_once("../common/footer.php"); } elseif($_SESSION['valid'] == false) { header("Location: ../../login.php"); } else { print "File Delete Unsuccessful"; } ?> Link to comment https://forums.phpfreaks.com/topic/156258-solved-if-post-url-do-this/ Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 30, 2009 Share Posted April 30, 2009 The best way is probably to do that : upload_images.php <a href="delupload.php?file=filename.jpg&type=image"></a> upload_audio.php <a href="delupload.php?file=filename.mp3&type=audio"></a> upload_video.php <a href="delupload.php?file=filename.avi&type=video"></a> And in delupload.php : <?php switch ($_GET['type']) { case 'audio' : /* code foir deleting audio file */ break; case 'video' : /* code foir deleting video file */ break; case 'image' : /* code foir deleting image file */ break; default : break; } ?> Of course you will need security to be sure the user has the right to delete the file. Link to comment https://forums.phpfreaks.com/topic/156258-solved-if-post-url-do-this/#findComment-822662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.