drisate Posted August 31, 2010 Share Posted August 31, 2010 Hey guys! Everytime i upload something to the server theres a files created called Resource id #10 (number increments after eachj upload) From what i can ubserve, those are the TMP file ... but for somereason it's staying there and piles up and takes out a lot of space. Is there a way to delete them when the upload is finished? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 31, 2010 Share Posted August 31, 2010 A) Exactly where are these files being created at, what folder? B) Your code is apparently using a file handle or a database link resource as the file name to save a file as and you would need to post your code if you want help with it. Quote Link to comment Share on other sites More sharing options...
drisate Posted September 1, 2010 Author Share Posted September 1, 2010 Here's my code function photo($image, $largeur_maximum, $destination){ $autorises = 'gifjpegjpgpngGIFJPEGJPGPNG'; $extension = explode('.', $destination); $extension = strtolower($extension[sizeof($extension) - 1]); if (ereg($extension, $autorises)) { $dimensions = getimagesize($image); $largeur_actuelle = $dimensions[0]; $hauteur_actuelle = $dimensions[1]; if ($largeur_maximum == "original") { $nouvelle_largeur = $dimensions[0]; $nouvelle_hauteur = $dimensions[1]; } else { if ($largeur_actuelle > $largeur_maximum) { $nouvelle_largeur = $largeur_maximum; $nouvelle_hauteur = $hauteur_actuelle / ($largeur_actuelle / $largeur_maximum); } else { $nouvelle_largeur = $dimensions[0]; $nouvelle_hauteur = $dimensions[1]; } } if ($extension == 'jpg' || $extension == 'jpeg') { $image_p = imagecreatetruecolor($nouvelle_largeur, $nouvelle_hauteur); $image = imagecreatefromjpeg($image); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $nouvelle_largeur, $nouvelle_hauteur, $largeur_actuelle, $hauteur_actuelle); imagejpeg($image_p, $image); } else if ($extension == 'gif') { $image_p = imagecreatetruecolor($nouvelle_largeur, $nouvelle_hauteur); $image = imagecreatefromgif($image); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $nouvelle_largeur, $nouvelle_hauteur, $largeur_actuelle, $hauteur_actuelle); imagegif($image_p, $image); } else if ($extension == 'png') { $wm = imagecreatefrompng($image); //Position du WM sur l'image finale $positionx = 0; $positiony = 0; //Calcul de l'image du watermark $largeurW = imagesx($wm); $hauteurW = imagesy($wm); //Si l'image source est plus large que celle du WM, on effectue la mise en place du WM if ($largeurSrc > $largeurW) { # Création de l'image finale aux dimensions de l'image qui va accueillir le WM $final = imagecreatetruecolor($largeurSrc, $hauteurSrc); # configuration du canal alpha pour le WM imagealphablending($wm, false); imagesavealpha($wm, true); # Ajout du watermark imagecopyresampled($final, $wm, $positionx, $positiony, 0, 0, $largeurW, $hauteurW, $largeurW, $hauteurW); # Pour ajouter d'autre photo par dessus, procéder de la meme façon # affichage de l'image finale header("Content-type: image/png"); imagepng($image); } } copy($image, $destination); } } when i wana upload a file i simply do this: $rand = rand("1000", "90000") . "-"; $name = $rand . nomValide($_FILES['image']['name']); photo($_FILES['image']['tmp_name'],$media_small_whidth,'../'.$media_small.$name); photo($_FILES['image']['tmp_name'],$media_medium_whidth,'../'.$media_medium.$name); photo($_FILES['image']['tmp_name'],$media_medbig_whidth,'../'.$media_medbig.$name); photo($_FILES['image']['tmp_name'],$media_big_whidth,'../'.$media_big.$name); photo($_FILES['image']['tmp_name'],'original','../'.$media_original.$name); This creates 4 version of the same photo with diffrent width + the original format. All versions are used in the site depending of the page. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2010 Share Posted September 1, 2010 Your code is reusing the $image variable to hold the GD image resource, so when you use $image later in the code as the name for the file, you get files named like Resource id #10... I suspect that the code wanted to use the $destination variable as the second parameter in the imagejpeg(), imagegif(), imagepng() statements so that the resulting images would be stored directly in the destination. Quote Link to comment Share on other sites More sharing options...
drisate Posted September 1, 2010 Author Share Posted September 1, 2010 No sure i will be able to use the same function 4 times if the tmp file is not there anymore right? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2010 Share Posted September 1, 2010 I suspect that the code wanted to use the $destination variable as the second parameter in the imagejpeg(), imagegif(), imagepng() statements so that the resulting images would be stored directly in the destination. Quote Link to comment Share on other sites More sharing options...
drisate Posted September 1, 2010 Author Share Posted September 1, 2010 What if i do something like this at the end function delete_photo_tmp (){ $myDirectory = opendir("."); while($entryName = readdir($myDirectory)) { $dirArray[] = $entryName; } closedir($myDirectory); $indexCount = count($dirArray); sort($dirArray); for($index=0; $index < $indexCount; $index++) { if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files if ( strstr($dirArray[$index], "Ressource id #") ) { unlink("$dirArray[$index]"); } } } } Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2010 Share Posted September 1, 2010 Why don't you just directly store the images at the final destination as has been suggested? What you are doing now won't work when you have multiple concurrent visitors because the intermediate output filenames are not unique and files can get overwritten before you copy them to the final destination. Quote Link to comment 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.