virtuexru Posted November 22, 2006 Share Posted November 22, 2006 Ok. So I have a table setup with User ID, Their Name, the type of Doc or whatever in BLOB format.I would like to know a safe way to be able to let the users delete their files. This is my upload scheme:[quote] $ncheck= $_SESSION['results'][fullname]; $query = "SELECT id, name FROM *** WHERE name = '$ncheck'"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "<b>You have not uploaded a resume yet, please do so now.</b><br>"; if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_SESSION['results'][fullname]; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $query = "INSERT INTO resumes (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, upload failed'); echo "Your file named: <b>".$fileName.".doc</b> has been uploaded.<br/> Thank you.<br/>";[/quote] Link to comment https://forums.phpfreaks.com/topic/28123-allowing-users-to-delete-uploaded-files/ Share on other sites More sharing options...
CheesierAngel Posted November 22, 2006 Share Posted November 22, 2006 ALTER TABLE resumes ADD COLUMN userId int NOT NULL;Then you have a history of which user uploaded which resume, and you can restrict the user todelete only his resumes. Link to comment https://forums.phpfreaks.com/topic/28123-allowing-users-to-delete-uploaded-files/#findComment-128619 Share on other sites More sharing options...
virtuexru Posted November 22, 2006 Author Share Posted November 22, 2006 Thank you for the response. I get the idea but how would I implement this in code? I would basically have a unique ID increment for each user and allow them to DROP that row only? Link to comment https://forums.phpfreaks.com/topic/28123-allowing-users-to-delete-uploaded-files/#findComment-128621 Share on other sites More sharing options...
CheesierAngel Posted November 22, 2006 Share Posted November 22, 2006 [code]<?phpif(isset($_GET['delete'])) { // delete the row}$ncheck= $_SESSION['results'][fullname]; $query = "SELECT id, name FROM *** WHERE name = '$ncheck' LIMIT 1";$result = mysql_query($query) or die('Error, query failed' . mysql_error());$user = mysql_fetch_array($result);$query = "SELECT * FROM resumes";$result = mysql_query($query) or die('Error query failed' . mysql_error());$output = <<<HTML <table> <tr> <th>name</th> <th>size</th> <th>type</th> <th>content</th> <th>actions</th> </tr>HTML;while($resume = mysql_fetch_object($result)) { $output .= <<<HTML <tr> <td>$resume->name</td> <td>$resume->size</td> <td>$resume->type</td> <td>$resume->content</td> <td>HTML; $output .= $resume->userId == $userId ? '<a href="thispage.php?delete="' . $resume->id . '">delete</a>' : 'no actions available'; $output .= <<<HTML </td> </tr>HTML;}$output .= <<<HTML </table>HTML;echo $output;?>[/code]Or something like this.... Link to comment https://forums.phpfreaks.com/topic/28123-allowing-users-to-delete-uploaded-files/#findComment-128634 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.