xcoderx Posted November 12, 2009 Share Posted November 12, 2009 guys i got a script that would store info in a txt file with numbers e.g 33004488.txt and the link gets sent to a person in an email so that he/she can view the content. so what i want to do is once the person visits the content the 33004488.txt files gets deleted from the folder. Quote Link to comment https://forums.phpfreaks.com/topic/181273-solved-how-would-one-ulink-a-file-once-visited/ Share on other sites More sharing options...
xcoderx Posted November 12, 2009 Author Share Posted November 12, 2009 here is the part <?php } else if ( (!isset($_POST['submit'])) && (isset($_GET['displayinfo'])) ) { $file = isset($_GET['displayinfo']) ? $_GET['displayinfo'] : '' ; $content = file('messages/'.$file.".txt"); $pic = $content['0']; unset ($content['0']); unset ($content['1']); $main = ""; foreach ($content as $value) { $main .= $value; } ?> <center>Here Is Your E-Card!<br/><br/> <img src='thumbs/<?php echo $pic; ?>' alt="E-Card" /> <br/><br/><br/> <?php echo nl2br(htmlspecialchars($main)); ?> </center> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/181273-solved-how-would-one-ulink-a-file-once-visited/#findComment-956294 Share on other sites More sharing options...
Garethp Posted November 12, 2009 Share Posted November 12, 2009 Well, this should help you http://ryanfait.com/resources/protect-flash-files-from-download/ Basically the concept is to load the file in a PHP script, so they don't see the file itself, but a mirror copy of the file. Use that, but after first run, delete the orriginal file Quote Link to comment https://forums.phpfreaks.com/topic/181273-solved-how-would-one-ulink-a-file-once-visited/#findComment-956296 Share on other sites More sharing options...
xcoderx Posted November 12, 2009 Author Share Posted November 12, 2009 not helping gareth i basically want the text file get deleted once the person views the particular numbered file he recieves with the email Quote Link to comment https://forums.phpfreaks.com/topic/181273-solved-how-would-one-ulink-a-file-once-visited/#findComment-956304 Share on other sites More sharing options...
Garethp Posted November 12, 2009 Share Posted November 12, 2009 Yes, so you mail them a link to a PHP file with the number attached on the end, ?ID=Number You then have the PHP file read the txt file, display the contents, then delete the txt file Quote Link to comment https://forums.phpfreaks.com/topic/181273-solved-how-would-one-ulink-a-file-once-visited/#findComment-956307 Share on other sites More sharing options...
darkvengance Posted November 12, 2009 Share Posted November 12, 2009 ..first off,sorry if this isn't what you are looking for I just woke up and am still in between worlds lol... but here is something that I think you are talking about...however it is very insecure, but still it should work if you filter it out, and it's only txt files you are showing... <?php $id=$_GET['id']; //This would be the name of the originall file include("/home/public_html/uploaded/".$id); //Use include to show the file unlink("/home/public_html/uploaded/".$id); //Use unlink to delete the file ?> Quote Link to comment https://forums.phpfreaks.com/topic/181273-solved-how-would-one-ulink-a-file-once-visited/#findComment-956308 Share on other sites More sharing options...
darkvengance Posted November 12, 2009 Share Posted November 12, 2009 Here is one that is a little better: <?php $id=$_GET['id']; //This would be the name of the originall file $page = file_get_contents('http://www.yoursite.com/pages/'.$id); echo $page; unlink("/home/public_html/pages/".$id); ?> Quote Link to comment https://forums.phpfreaks.com/topic/181273-solved-how-would-one-ulink-a-file-once-visited/#findComment-956309 Share on other sites More sharing options...
xcoderx Posted November 12, 2009 Author Share Posted November 12, 2009 this is what i tried <?php } else if ( (!isset($_POST['submit'])) && (isset($_GET['displayinfo'])) ) { $file = isset($_GET['displayinfo']) ? $_GET['displayinfo'] : '' ; $content = file('messages/'.$file.".txt"); $pic = $content['0']; unset ($content['0']); unset ($content['1']); $main = ""; foreach ($content as $value) { $main .= $value; } ?> delete should be done somewhere here <center>Here Is Your E-Card!<br/><br/> <img src='thumbs/<?php echo $pic; ?>' alt="E-Card" /> <br/><br/><br/> <?php echo nl2br(htmlspecialchars($main)); $main = file('messages/'.$file.".txt"); unlink($main); ?> and i get this error Warning: unlink() expects parameter 1 to be string, array given in /home2/public_html/card.php on line 142 Quote Link to comment https://forums.phpfreaks.com/topic/181273-solved-how-would-one-ulink-a-file-once-visited/#findComment-956317 Share on other sites More sharing options...
darkvengance Posted November 12, 2009 Share Posted November 12, 2009 That's because you are using: $main = file('messages/'.$file.".txt"); unlink($main); When it should be: $main = 'messages/'.$file.'.txt'; unlink($main); Quote Link to comment https://forums.phpfreaks.com/topic/181273-solved-how-would-one-ulink-a-file-once-visited/#findComment-956320 Share on other sites More sharing options...
xcoderx Posted November 12, 2009 Author Share Posted November 12, 2009 thanks brothers it was this $content = 'messages/'.$file.'.txt'; unlink($content); :-) solved Quote Link to comment https://forums.phpfreaks.com/topic/181273-solved-how-would-one-ulink-a-file-once-visited/#findComment-956329 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.