Jump to content

Recommended Posts

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]<?php
if( $_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.php
So 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.
well if it is giving you that error message, it means that $_SESSION['thumb'] is not set. Maybe you want

[code]
<?php
if( $_SESSION['thumb'] != "nopic.jpg" && $_SESSION['thumb']!="") {
unlink("shared_files/thumbs/".$_SESSION['thumb']);
?>
[/code]
That fixed the warning, thanks

But It still won't replace the old thumb like it does the old original size, thumbs still lingering
I just can't see why, the original size gets swapped out just perfectly.
Thumbs don't swap out, they build up,lol. hmmmm

Any more ideas?
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]<?php
if( $_SESSION['photo'] != "nopic.jpg" && $_SESSION['photo']!="") {
unlink("shared_files/thumbs/".$_SESSION['photo']);
?>[/code]

Regards
Huggie
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 you
Another satisfied customer
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.

Regards
Huggie
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.