Jump to content

Photo upload


drisate

Recommended Posts

Hey guys i am having issues making this code work

 

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);
}
}

 

This is teh error:

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'Resource id #8' for writing in /var/www/vhosts/automobilesdmr.com/httpdocs/administration/head.php on line 97

 

Warning: copy(Resource id #8) [function.copy]: failed to open stream: No such file or directory in /var/www/vhosts/automobilesdmr.com/httpdocs/administration/head.php on line 109

 

// line 97
imagejpeg($image_p,$image);

// line 109
copy($image,$destination);

Link to comment
https://forums.phpfreaks.com/topic/169129-photo-upload/
Share on other sites

Warning: copy(Resource id #8) [function.copy]: failed to open stream: No such file or directory in /var/www/vhosts/automobilesdmr.com/httpdocs/administration/head.php on line 109

 

that means the directory you are trying to write to doesn't exist

 

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'Resource id #8' for writing in /var/www/vhosts/automobilesdmr.com/httpdocs/administration/head.php on line 97

 

this i believe means you don't have to correct rights to write data to that file.

Link to comment
https://forums.phpfreaks.com/topic/169129-photo-upload/#findComment-892351
Share on other sites

Thats impossible ...

 

the script is located at:

httpdocs/administration/inventaire.php

 

The code that calls the function looks like this:

$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++;

}

 

All directorys exists and are chomoded to 777

 

httpdocs/media

httpdocs/media/big

httpdocs/media/medium

httpdocs/media/original

httpdocs/media/small

 

the copy(Resource id #8) error is caused because Resource id #8 is not the value that is suposed to be there ... thats where the script fucks up. why is that there? and How to repaire it?

Link to comment
https://forums.phpfreaks.com/topic/169129-photo-upload/#findComment-892359
Share on other sites

Warning: copy(Resource id #8) [function.copy]: failed to open stream: No such file or directory in /var/www/vhosts/automobilesdmr.com/httpdocs/administration/head.php on line 109

 

that means the directory you are trying to write to doesn't exist

 

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'Resource id #8' for writing in /var/www/vhosts/automobilesdmr.com/httpdocs/administration/head.php on line 97

 

this i believe means you don't have to correct rights to write data to that file.

 

trudat

Link to comment
https://forums.phpfreaks.com/topic/169129-photo-upload/#findComment-892418
Share on other sites

Warning: copy(Resource id #8) [function.copy]: failed to open stream: No such file or directory in /var/www/vhosts/automobilesdmr.com/httpdocs/administration/head.php on line 109

 

that means the directory you are trying to write to doesn't exist

 

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'Resource id #8' for writing in /var/www/vhosts/automobilesdmr.com/httpdocs/administration/head.php on line 97

 

this i believe means you don't have to correct rights to write data to that file.

 

trudat

 

No the path is good look

 

Script is here

httpdocs/administration/inventaire.php

 

The script is:

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]));

 

The files EXISTE and are all chomoded to 777 there location are:

 

httpdocs/media

httpdocs/media/big

httpdocs/media/medium

httpdocs/media/original

httpdocs/media/small

 

So the path is good has to be something else.

Link to comment
https://forums.phpfreaks.com/topic/169129-photo-upload/#findComment-892591
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.