Jump to content

Recommended Posts

http://track9.info/info.php this is my phpinfo

 

I'm using the following code;

 

$fileName = $_FILES["uploadfile"]["name"];
// get the file extension first
$ext = substr(strrchr($fileName, "."), 1);
// make the random file name
do{
$randName = md5(rand() * time());
$pass = "$randName.$ext";
$Check = (file_exists("upimg/$pass") || file_exists("thimg/$pass") || file_exists("avimg/$pass"));
}while( $Check );
$uploadedfile = $_FILES["uploadfile"]["tmp_name"];

list($width,$height)=getimagesize($uploadedfile);

$newwidth1=600;
$newwidth2=180;
$newwidth3=100;
$newheight1=($height/$width)*600;
$newheight2=($height/$width)*180;
$newheight3=($height/$width)*100;

switch($_FILES['uploadfile']['type'])
{
case "image/gif":
	$src = imagecreatefromgif($uploadedfile);//Create from GIF!
	$type = "gif";
break;
case "image/jpg":
case "image/jpeg":
	$src = imagecreatefromjpeg($uploadedfile);//Create from JPEG!
	$type = "jpg";
break;
}
#1
//$src = imagecreatefromjpeg($uploadedfile);//Create from JPEG!
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);
imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);
$filename = "upimg/$pass";// . $_FILES["uploadfile"]["name"];
if($type == "gif")
{
imagegif($tmp1,$filename,100);
}elseif($type == "jpg"){
imagejpeg($tmp1,$filename,100);
}
imagedestroy($src);

#2
$tmp2=imagecreatetruecolor($newwidth2,$newheight2);
imagecopyresampled($tmp2,$tmp1,0,0,0,0,$newwidth2,$newheight2,$newwidth1,$newheight1);
$filename = "thimg/$pass";// . $_FILES["uploadfile"]["name"];
if($type == "gif")
{
imagegif($tmp2,$filename,100);
}elseif($type == "jpg"){
imagejpeg($tmp2,$filename,100);
}
imagedestroy($tmp1);

#3
$tmp3=imagecreatetruecolor($newwidth3,$newheight3);
imagecopyresampled($tmp3,$tmp2,0,0,0,0,$newwidth3,$newheight3,$newwidth2,$newheight2);
$filename = "avimg/$pass";// . $_FILES["uploadfile"]["name"];
if($type == "gif")
{
imagegif($tmp3,$filename,100);
}elseif($type == "jpg"){
imagejpeg($tmp3,$filename,100);
}
imagedestroy($tmp2);
imagedestroy($tmp3);

$name = $_FILES["uploadfile"]["name"];
}

 

Can upload fine using firefox, but using internet explorer get this;

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/u2/ozaki12/html/track9/newt9/PHP_FILES/uploader.php on line 49

 

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/u2/ozaki12/html/track9/newt9/PHP_FILES/uploader.php on line 57

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/73546-solved-image-upload-resize/
Share on other sites

<form action="index.php?pageid=31" method="post" enctype="multipart/form-data">
<p><b>Supported Formats: JPG,GIF ONLY!</b></p>
<p>
<input type="file" name="uploadfile">
</p>
<p>Caption: <br>
<input type="text" name="caption" size="20"></p>
<p>Default:</p>
<p>Yes<input type="radio" value="1" name="default" checked><br>
No<input type="radio" value="0" name="default"></p>
<p><b>Max File Size: 2mb.</b></p>
<p>* This may take a long time! *</p>
<p>
<input type="submit" name="Upload" value="Upload Picture"/> </p>

Hummm..

only problem i can see is an extra } at the end of the php script..

 

my test works fine..

<?php
if(isset($_FILES))
{
$fileName = $_FILES["uploadfile"]["name"];
// get the file extension first
$ext = substr(strrchr($fileName, "."), 1);
// make the random file name
do{
$randName = md5(rand() * time());
$pass = "$randName.$ext";
$Check = (file_exists("upimg/$pass") || file_exists("thimg/$pass") || file_exists("avimg/$pass"));
}while( $Check );
$uploadedfile = $_FILES["uploadfile"]["tmp_name"];

list($width,$height)=getimagesize($uploadedfile);

$newwidth1=600;
$newwidth2=180;
$newwidth3=100;
$newheight1=($height/$width)*600;
$newheight2=($height/$width)*180;
$newheight3=($height/$width)*100;

switch($_FILES['uploadfile']['type'])
{
case "image/gif":
	$src = imagecreatefromgif($uploadedfile);//Create from GIF!
	$type = "gif";
break;
case "image/jpg":
case "image/jpeg":
	$src = imagecreatefromjpeg($uploadedfile);//Create from JPEG!
	$type = "jpg";
break;
}
#1
//$src = imagecreatefromjpeg($uploadedfile);//Create from JPEG!
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);
imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);
$filename = "upimg/$pass";// . $_FILES["uploadfile"]["name"];
if($type == "gif")
{
imagegif($tmp1,$filename,100);
}elseif($type == "jpg"){
imagejpeg($tmp1,$filename,100);
}
imagedestroy($src);

#2
$tmp2=imagecreatetruecolor($newwidth2,$newheight2);
imagecopyresampled($tmp2,$tmp1,0,0,0,0,$newwidth2,$newheight2,$newwidth1,$newheight1);
$filename = "thimg/$pass";// . $_FILES["uploadfile"]["name"];
if($type == "gif")
{
imagegif($tmp2,$filename,100);
}elseif($type == "jpg"){
imagejpeg($tmp2,$filename,100);
}
imagedestroy($tmp1);

#3
$tmp3=imagecreatetruecolor($newwidth3,$newheight3);
imagecopyresampled($tmp3,$tmp2,0,0,0,0,$newwidth3,$newheight3,$newwidth2,$newheight2);
$filename = "avimg/$pass";// . $_FILES["uploadfile"]["name"];
if($type == "gif")
{
imagegif($tmp3,$filename,100);
}elseif($type == "jpg"){
imagejpeg($tmp3,$filename,100);
}
imagedestroy($tmp2);
imagedestroy($tmp3);

$name = $_FILES["uploadfile"]["name"];
}

?>
<form method="post" enctype="multipart/form-data">
<p><b>Supported Formats: JPG,GIF ONLY!</b></p>
<p>
<input type="file" name="uploadfile">
</p>
<p>Caption: <br>
<input type="text" name="caption" size="20"></p>
<p>Default:</p>
<p>Yes<input type="radio" value="1" name="default" checked><br>
No<input type="radio" value="0" name="default"></p>
<p><b>Max File Size: 2mb.</b></p>
<p>* This may take a long time! *</p>
<p>
<input type="submit" name="Upload" value="Upload Picture"/> </p>

But it works.. ???

 

ooow Okay one thing..

 

try this

switch($_FILES['uploadfile']['type'])
{
case "image/gif":
	$src = imagecreatefromgif($uploadedfile);//Create from GIF!
	$type = "gif";
break;
case "image/jpg":
case "image/pjpeg": //Add this (photoshop jpeg)
case "image/jpeg":
	$src = imagecreatefromjpeg($uploadedfile);//Create from JPEG!
	$type = "jpg";
break;
}

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.