alwaysinit Posted October 25, 2006 Share Posted October 25, 2006 Could some one show me how to go about unlinking, or replacing my user's old thumbnails. They're all sticking around taking up space.I tried to do it as it is done for the original size image(original unlinks fine) in this script by adding:[code]<?phpif( $_SESSION['thumb'] != "nopic.jpg" ) { unlink("shared_files/thumbs/".$_SESSION['thumb']); }?>[/code]Which gives me the warning: "shared_files/thumbs/" Is a directory in /home/myname/mydomain/changephotoparse.phpSo below is the code if I can impose upon you( I've commented where I tried to place the above code)[code]<?php session_start(); header("Cache-control: private"); include("db_connect.php"); function create_resize_save_jpeg( $path, $newpath ) { list( $width_orig, $height_orig ) = getimagesize( $path ); $image_p = imagecreatetruecolor( 150, 150); if( !$image = imagecreatefromjpeg( $path ) ) { $_SESSION['errormsg'] = "Cant create photo!"; } else { imagecopyresampled($image_p, $image, 0, 0, 0, 0, 150, 150, $width_orig, $height_orig); imagejpeg($image_p, $newpath, 100); }}function create_resize_save_gif( $path, $newpath, $max = 150) { $w = $h = $max; list( $width_orig, $height_orig ) = getimagesize( $path ); if($width_orig < $height_orig) $w = round(($h / $height_orig) * $width_orig); else $h = round(($w / $width_orig) * $height_orig); $image_p = imagecreatetruecolor($w, $h); if( !$image = imagecreatefromgif( $path ) ) { $_SESSION['errormsg'] = "Cant create photo!"; } else { imagecopyresampled($image_p, $image, 0, 0, 0, 0, $w, $h, $width_orig, $height_orig); imagegif($image_p, $newpath, 100); } imagedestroy($image_p); imagedestroy($image); }function create_resize_save_png( $path, $newpath ) { list( $width_orig, $height_orig ) = getimagesize( $path ); $image_p = imagecreatetruecolor( 150, 150); if( !$image = imagecreatefrompng( $path ) ) { $_SESSION['errormsg'] = "Cant create proto!"; } else { imagecopyresampled($image_p, $image, 0, 0, 0, 0, 150, 150, $width_orig, $height_orig); imagepng($image_p, $newpath, 100); }}function file_extention( $str ) { $size = strlen($str); $x=0; while($x < $size) { if($str[$x] == '.') { $ext = ""; $ext_len = ($size - $x); $y=$x; while($y < $size) { $ext .= $str[$y]; $y++; } } $x++; }return $ext;}if( !$_SESSION['artname'] ) { echo "You're not logged in!"; include("login.html"); exit(); } $artname = $_SESSION['artname']; $maxfilesize = 81920; if( !is_uploaded_file( $_FILES['userphoto']['tmp_name'] ) ) { $error = "you didn't select a file to upload.<br />"; } else { if( $_FILES['userphoto']['size'] > $maxfilesize ) { $error = "your image file was too large.<br />"; unlink($_FILES['userphoto']['tmp_name']); } else { if( !preg_match("/\.(gif|jpg|png)$/i", $_FILES['userphoto']['name'] ) ) { $error = "your file was an unacceptable type.<br />"; unlink($_FILES['userphoto']['tmp_name']); } else { $ext = file_extention( $_FILES['userphoto']['name'] ); if( $_SESSION['photo'] != "nopic.jpg" ) { unlink("shared_files/photos/".$_SESSION['photo']); } // **********This is where I tried to pop that code in************ // **************************************************** $newname = $_SESSION['artname'].$_FILES['userphoto']['name']; if( !move_uploaded_file( $_FILES['userphoto']['tmp_name'], "shared_files/photos/".$newname ) ) { $error = "problems moving uploaded file.<br />"; } else { $_SESSION['photo'] = $newname; if( $ext == ".jpg" ) { create_resize_save_jpeg("shared_files/photos/".$newname, "shared_files/thumbs/".$newname); } else if( $ext == ".gif" ) { create_resize_save_gif("shared_files/photos/".$newname, "shared_files/thumbs/".$newname); } else if( $ext == ".png" ) { create_resize_save_png("shared_files/photos/".$newname, "shared_files/thumbs/".$newname); } mysql_query("UPDATE peepsignup SET photo='$newname' WHERE artname='$artname'") or die (mysql_error()); $_SESSION['photo'] = $newname; mysql_query("UPDATE peepsignup SET thumb='$newname' WHERE artname='$artname'") or die (mysql_error()); $_SESSION['photo'] = $newname; } } } }?> <html><head><title>Change Photo Result</title></head><body> <h1>Change Photo Result</h1> <?php if ($error) { echo "Your photo could not be changed because ".$error."."; } else { echo "Your photo was successfully uploaded. To view your updated profile, <a href=\"memberarea.php\">click here</a>."; } ?></body></html> [/code]Thanks for any push in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/25082-old-thumbnails-are-lingering-in-my-file-system/ Share on other sites More sharing options...
ksteuber Posted October 25, 2006 Share Posted October 25, 2006 well if it is giving you that error message, it means that $_SESSION['thumb'] is not set. Maybe you want[code]<?phpif( $_SESSION['thumb'] != "nopic.jpg" && $_SESSION['thumb']!="") { unlink("shared_files/thumbs/".$_SESSION['thumb']);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25082-old-thumbnails-are-lingering-in-my-file-system/#findComment-114343 Share on other sites More sharing options...
alwaysinit Posted October 25, 2006 Author Share Posted October 25, 2006 That fixed the warning, thanksBut It still won't replace the old thumb like it does the old original size, thumbs still lingeringI just can't see why, the original size gets swapped out just perfectly. Thumbs don't swap out, they build up,lol. hmmmmAny more ideas? Quote Link to comment https://forums.phpfreaks.com/topic/25082-old-thumbnails-are-lingering-in-my-file-system/#findComment-114354 Share on other sites More sharing options...
HuggieBear Posted October 25, 2006 Share Posted October 25, 2006 I can't see where you've defined [code=php:0]$_SESSION['thumb'][/code]?My guess is that you've put the thumbs into a directory called thumbs, but given them the same name as the large image, in which case try this:[code]<?phpif( $_SESSION['photo'] != "nopic.jpg" && $_SESSION['photo']!="") { unlink("shared_files/thumbs/".$_SESSION['photo']);?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25082-old-thumbnails-are-lingering-in-my-file-system/#findComment-114360 Share on other sites More sharing options...
alwaysinit Posted October 25, 2006 Author Share Posted October 25, 2006 I'll work it out, But you guys got me a lot closer a lot quicker, thanks Quote Link to comment https://forums.phpfreaks.com/topic/25082-old-thumbnails-are-lingering-in-my-file-system/#findComment-114367 Share on other sites More sharing options...
alwaysinit Posted October 25, 2006 Author Share Posted October 25, 2006 Nope I was wrong, Whatever you guys did worked for me!Now, could I push for a brief explanation?(what did this "&& $_SESSION['thumb']!="")" do ?(Huggie, I defined $_SESSION['thumb'] in my first block of code up there)Thank you, thank you, thank youAnother satisfied customer Quote Link to comment https://forums.phpfreaks.com/topic/25082-old-thumbnails-are-lingering-in-my-file-system/#findComment-114382 Share on other sites More sharing options...
ksteuber Posted October 25, 2006 Share Posted October 25, 2006 I agree with HuggieBear, I dont see where you defined $_Session['thumb'] Quote Link to comment https://forums.phpfreaks.com/topic/25082-old-thumbnails-are-lingering-in-my-file-system/#findComment-114386 Share on other sites More sharing options...
alwaysinit Posted October 25, 2006 Author Share Posted October 25, 2006 Ok, now I'm just confused about this thumb session bit, What do you guys mean? Quote Link to comment https://forums.phpfreaks.com/topic/25082-old-thumbnails-are-lingering-in-my-file-system/#findComment-114387 Share on other sites More sharing options...
HuggieBear Posted October 25, 2006 Share Posted October 25, 2006 When I say define, I mean assign a value to it, something like this:[code=php:0]$_SESSION['thumb'] = "smallthumb.jpg";[/code]Nowhere in your code do you assign anything to a session variable called 'thumb'. So by looking at the code, I assumed you'd just copied one block that deleted the photo and changed the values to try and delete the thumbnails. The theory is almost right, but the practice not quite, hence why I got you to change the name to [code=php:0]$_SESSION['photo'][/code] as I know it existed, and you were calling your thumbs by the same name.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25082-old-thumbnails-are-lingering-in-my-file-system/#findComment-114491 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.