Jump to content

Help me please


Huggy86

Recommended Posts

Hello,

 

I have been trying to get a image resizer working on a new website that I have been making. The problem is when I try to resize the image I am not getting anywhere.

 

I downloaded a free function which does it for me the function is below,

 

function resize_image($file, $w, $h, $crop=FALSE) {

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

    $newwidth = $w;
    $newheight = $h;

    $src = imagecreatefromjpeg($file);
    $dst = imagecreatetruecolor($newwidth, $newheight);
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    return $dst;
}

 

This is the uploader,

 

<?php

if(!$_SESSION[$prefix.'loggeduser'])

	{

	header("Location:index.php?a=login&message=register");
	exit(0);

	}

//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","1000"); 

//This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
}

//This variable is used as a flag. The value is initialized with 0 (meaning no error  found)  
//and it will be changed to 1 if an errro occures.  
//If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit'])) 
{

	//reads the name of the file the user submitted for uploading
	$image=$_FILES['image']['name'];
	//if it is not empty
	if ($image) 
	{
	//get the original name of the file from the clients machine
		$filename = stripslashes($_FILES['image']['name']);
	//get the extension of the file in a lower case format
  		$extension = getExtension($filename);
		$extension = strtolower($extension);
	//if it is not a known extension, we will suppose it is an error and will not  upload the file,  
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
		{
	//print error message
			echo '<h3>Unknown extension!</h3>';
			$errors=1;
		}
		else
		{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
echo '<h3>You have exceeded the size limit!</h3>';
$errors=1;
}

	$title = clean($_POST['title']);

	$category = clean($_POST['category']);

	//$size = clean($_POST['size']);

//we will give an unique name, for example the time in unix time format

$image_name=time().'.'.$extension;

$temp = "uploads/temp/$image_name";

$newname = "uploads/temp/$image_name";

//we verify if the image has been uploaded, and print error instead

$copied = copy($_FILES['image']['tmp_name'], $newname);

// resize the image

$img = resize_image($_FILES['image']['tmp_name'], 1024, 768);

imagejpeg($img,"uploads/1024x768/$newname",80);

//$img1 = resize_image($_FILES['image']['tmp_name'], 1280, 1024);

//imagejpeg($img1,"uploads/1280x1024/$newname",80);

// update db

mysql_query("INSERT INTO wallpapers (title,category,posted,user,imagelink,sizes) VALUES ('$title','$category','".time()."','".$_SESSION[$prefix.'loggeduser']."','$newname','1024x768 1280x1024')") or die (mysql_error());

		}

	}
}

//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors) 
{
	echo "<h3>File Uploaded Successfully! Try again!</h3>";
}

?>

<!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" -->
<form name="newad" method="post" enctype="multipart/form-data"  action="">
   <p>Filename: <input type="text" name="title" id="title"></p>
  
  <p>Category: <select name="category"><?php echo listcats(); ?></select></p>
  <p>Size: <select name="size"><option value="1280x1024">1280x1024</option><option value="1024x768">1024x768</option></select></p>
<p>File: <input type="file" name="image"></p>
	<p><input name="Submit" type="submit" value="Upload image"></p>	
</form>

 

Please note this is a mess, but it should be working from what I can see, I have checked that the GD is on and it is, can anyone see anywhere im going wrong?

 

Thankyou.

Link to comment
Share on other sites

I am not getting anywhere.

That does not tell us any relevant information.

 

To get help from someone who is not standing right next to you, you must communicate what exactly you did and what the results, symptoms, or errors are and at what point during what you did they occurred at.  :examine:

Link to comment
Share on other sites

Hello,

 

Sorry, I am not getting any error messages at the moment, it is just not doing anything.

 

What do you get if you place this after your opening <?php tag?

ini_set('display_errors',1);
error_reporting(E_STRICT);

 

This should display unmentioned errors.

Link to comment
Share on other sites

The only error that was shown, stated something about the date stamp, but no errors happend when I uploaded the image.

 

Date error (This is on all pages)

 

Strict Standards: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PST/-8.0/no DST' instead in /var/www/vhosts/joomix.com/httpdocs/inc.config.php on line 9

Link to comment
Share on other sites

Ok these errors have now come since I changed it to that error reporting,

 

 

Notice: Undefined variable: prefix in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 3

 

Warning: copy() [function.copy]: Unable to access uploads/temp/1264230280.jpg in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 83

 

Warning: copy(uploads/temp/1264230280.jpg) [function.copy]: failed to open stream: No such file or directory in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 83

 

Warning: imagejpeg() [function.imagejpeg]: Unable to access uploads/1024x768/uploads/temp/1264230280.jpg in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 89

 

Warning: imagejpeg() [function.imagejpeg]: Invalid filename in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 89

 

Notice: Undefined variable: prefix in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 97

Link to comment
Share on other sites

Ok these errors have now come since I changed it to that error reporting,

 

 

Notice: Undefined variable: prefix in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 3

 

Warning: copy() [function.copy]: Unable to access uploads/temp/1264230280.jpg in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 83

 

Warning: copy(uploads/temp/1264230280.jpg) [function.copy]: failed to open stream: No such file or directory in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 83

 

Warning: imagejpeg() [function.imagejpeg]: Unable to access uploads/1024x768/uploads/temp/1264230280.jpg in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 89

 

Warning: imagejpeg() [function.imagejpeg]: Invalid filename in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 89

 

Notice: Undefined variable: prefix in /var/www/vhosts/joomix.com/httpdocs/files/submit.php on line 97

 

Looks like you need to set permissions (via FTP) on those folders. uploads/1024x768/uploads/temp/ and recurse folders should be CHMODD'ed to 755. And also your undefined variables, you should add them beforehand. "$prefix = null;"

Link to comment
Share on other sites

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.