mcmuney Posted January 17, 2008 Share Posted January 17, 2008 I'm starting a free image hosting site, which will be stored in various folders (named based on date). I'd like to delete all images that are not being linked to (is that possible) or not being looked at for at least 60 days? How would this be tracked? Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/ Share on other sites More sharing options...
teng84 Posted January 17, 2008 Share Posted January 17, 2008 if you mean automatically delete them then this is cron's job Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441518 Share on other sites More sharing options...
predator Posted January 17, 2008 Share Posted January 17, 2008 we you will add the images to a database (just the location where they are found and the last date they was looked at) once you have that information it is simple you add a script that runs when you want to run it (really run it through an admin area would be best) The script looks through the records to see if an image has not been looked at for 60 days and you could do a loop through the folders to get the file names then compare them to the records in the database to see if they all match up if they do not delete the file. This is just a rough start and the file deletion could be optimized but i believe you should be able to get the idea from this. Regards Mark Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441521 Share on other sites More sharing options...
mcmuney Posted January 17, 2008 Author Share Posted January 17, 2008 I'm familiar with a cron job, but I'm not sure how I'd add the date on the DB. For example, if you're going to xyz.com/file.jpg directly, how can store that view to the DB? The visitor is going directly to the image and not on a page where you can add script to record the date on the DB? Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441526 Share on other sites More sharing options...
predator Posted January 17, 2008 Share Posted January 17, 2008 when a user uploads a new image just make it so a new record is added to the db with all the info needed (date uploaded, name of file, etc) Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441528 Share on other sites More sharing options...
mcmuney Posted January 17, 2008 Author Share Posted January 17, 2008 Yes, that's being done now. The image info is recorded in the DB. But how will I know that the uploaded image is being looked at? How will I determine that it can be deleted? Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441532 Share on other sites More sharing options...
teng84 Posted January 17, 2008 Share Posted January 17, 2008 instead of directly allowing the user to link on your images create php code that will output that images (trough header content type) then add the info of that image name in you db.. Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441534 Share on other sites More sharing options...
mcmuney Posted January 17, 2008 Author Share Posted January 17, 2008 Hmmm, that sounds interesting. Is there a sample or tutorial on it? Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441538 Share on other sites More sharing options...
teng84 Posted January 17, 2008 Share Posted January 17, 2008 this is only <a href="http://www.php.net/manual/en/function.header.php">header </a>so your browser know what kind of file to diplay Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441545 Share on other sites More sharing options...
mcmuney Posted January 17, 2008 Author Share Posted January 17, 2008 Oh, I C now... good call. Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441559 Share on other sites More sharing options...
mcmuney Posted January 17, 2008 Author Share Posted January 17, 2008 What's wrong with my code? I don't get any errors, but it's not writing to the DB: <?php include('db.php'); $date = $_GET['date']; $id = $_GET['id']; $time=date("m-d-y"); $sql = mysql_query("UPDATE images SET `last_view`='' AND `views`= views +'1' WHERE `id`='$id'") or die(mysql_error()); if (isset($_POST)){ header("Location: http://www.pickaloo.com/photos/$date/$id.jpg"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441620 Share on other sites More sharing options...
teng84 Posted January 17, 2008 Share Posted January 17, 2008 that is not exactly what i mean by the idea i gave you what i mean is that use PHP to display image any way that will work too. $sql = mysql_query("UPDATE images SET `last_view`='' AND `views`= views +1 WHERE `id`='$id'") or die(mysql_error()); try . and be sure that $id in not empty Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441625 Share on other sites More sharing options...
mcmuney Posted January 17, 2008 Author Share Posted January 17, 2008 Nope, still not working. I know id is not blank because it shows the image, which is based on the id. Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441627 Share on other sites More sharing options...
teng84 Posted January 17, 2008 Share Posted January 17, 2008 too bad i didnt see your error..try $sql = mysql_query("UPDATE images SET `last_view`='',`views`= views +1 WHERE `id`='$id'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441630 Share on other sites More sharing options...
mcmuney Posted January 17, 2008 Author Share Posted January 17, 2008 Bingo!!! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/86404-solved-deleting-files-that-are-not-hotlinked/#findComment-441633 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.