drisate Posted August 6, 2009 Share Posted August 6, 2009 Hey guys i have a javascript forme that lets the user create the number of photo upload box they need. I have been using this systeme in sevral other websites and now for some reason i am having problems using the form result ... I have 2 functions. The first une is to validate the name and the seconde one is to upload and resize. They both work because they are used elsewhere with no problems. function nomValide($tmp){ $accents = "ÀÃÂÃÄÅà áâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÃÃŽÃìÃîïÙÚÛÜùúûüÿÑñ"; $pasaccents = "aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn"; $autorises = ".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; $tmp = strtr($tmp,$accents,$pasaccents); for($i=0;$i<strlen($tmp);$i++){ if(!ereg($tmp{$i},$autorises)){ $tmp = str_replace($tmp{$i},'_',$tmp); } } return $tmp; } 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'){ $image_p = imagecreatetruecolor($nouvelle_largeur, $nouvelle_hauteur); $image = imagecreatefrompng($image); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $nouvelle_largeur, $nouvelle_hauteur, $largeur_actuelle, $hauteur_actuelle); imagepng($image_p,$image); } copy($image,$destination); } } And now for the code it self: $count = count($_FILES['userfile']['name']) - 1; //echo "Count is at :$count"; $x = 1; while ($x <= $count) { $rand = rand("1000", "90000") . "-"; //echo "- Image num: $x<br>"; if ($_FILES['userfile']['size'][$x] != "0") { echo "File name: $rand".$_FILES['userfile']['name'][$x]."<br>"; @photo($_FILES['userfile']['tmp_name'][$x],57,'../media/small/'.$rand.nomValide($_FILES['userfile']['name'][$x])); @photo($_FILES['userfile']['tmp_name'][$x],79,'../media/medium/'.$rand.nomValide($_FILES['userfile']['name'][$x])); @photo($_FILES['userfile']['tmp_name'][$x],300,'../media/big/'.$rand.nomValide($_FILES['userfile']['name'][$x])); @photo($_FILES['userfile']['tmp_name'][$x],'original','../media/original/'.$rand.nomValide($_FILES['userfile']['name'][$x])); $url=$rand.nomValide($_FILES['userfile']['name'][$x]); $insert = mysql_query("INSERT INTO photo (id, inv_id, photo, delfault) VALUE ('', '$last', '$url', '0')") or die(mysql_error()); } //echo "Relooping!<br>"; $x++; } I made a few a lot of debuging and heres what makes me go crazy ... $count returns the correct number of loops to do. echo "File name: $rand".$_FILES['userfile']['name'][$x]."<br>"; Returns the filename so the $_FILES var is well initiated. I made a print($_FILES) and everything is ok The @ of @photo is because of the notice but i tryed taking out the @ and there no fatal errors just a few anoying notices. But like i previously sayd the function is working fine in other projets i made so the code works. The files is chomoded to 777 and the linux groupe acess is ok The INSERT INTO works great ... every images are added to the database. BUT ... for some reason no images are uploaded ... WTF? The acess path are all good... the code loops ... the files name appears, the funtion works WHY??? lol Quote Link to comment Share on other sites More sharing options...
Adam Posted August 6, 2009 Share Posted August 6, 2009 What are the notices? Have you added debugging to check that: if(ereg($extension,$autorises)){ ... Is actually returning true? The code before it looks a little dodgy. Quote Link to comment Share on other sites More sharing options...
drisate Posted August 6, 2009 Author Share Posted August 6, 2009 wow i managed to get those errors out of my code imagejpeg() [function.imagejpeg]: Unable to open 'Resource id #8' for writing copy(Resource id # [function.copy]: failed to open stream: No such file or directory imagejpeg() [function.imagejpeg]: Unable to open 'Resource id #12' for writing copy(Resource id #12) [function.copy]: failed to open stream: No such file or directory imagejpeg() [function.imagejpeg]: Unable to open 'Resource id #16' for writing copy(Resource id #16) [function.copy]: failed to open stream: No such file or directory why is $_FILES['userfile']['tmp_name'][$x] returning a Resource id? Quote Link to comment Share on other sites More sharing options...
Adam Posted August 6, 2009 Share Posted August 6, 2009 It doesn't, imagecreatefromjpeg does. From the manual: imagecreatefromjpeg() returns an image identifier representing the image obtained from the given filename. You're using imagejpeg wrong. Have a look at the manual and then look at how you're using it. 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.