Jump to content

Help: Upload same image to 2 directories


clown[NOR]

Recommended Posts

I'm working on uploading an image file to 2 directories. One where it keeps it's original size, and one where I make the image 60x60.. I'm not sure what I'm doing wrong. It uploads to the images folder with no issues.. but it wont upload to the thumbs folder.. how come?

 

this is the code I've got atm:

<?php
		$fil = basename($_FILES['bilde']['name']);
		$ext = substr($fil, strrpos($fil, '.') + 1);
		echo "$fil<br>$ext";
		if (($ext == "jpg") || ($ext == "JPG") && ($_FILES['bilde']['type'] == "image/jpeg")) { $upload_Status = "ok"; }
		if (($ext == "gif") && ($_FILES['bilde']['type'] == "image/gif")) { $upload_Status = "ok"; }
		echo "$upload_Status<br>";
		if ($upload_Status == "ok") {
			$image_dir[0] = "images/uploads/members/images/";
			$image_dir[1] = "images/uploads/members/thumbs/";
			$image_path[0] = $image_dir[0].$fil;
			$image_path[1] = $image_dir[1].$fil;

			// TODO: Laste opp bilde. Både stort og lite.
			$tot = count($image_path);
			$i=0;
			while ($i < $tot) {
				echo "<br>$i<br>";
				move_uploaded_file($_FILES['bilde']['tmp_name'],$image_path[$i]);
				#chmod($image_path[$i], 0777);
				$newFilename = $fornavn.$etternavn;
				$newFilename = str_replace(".", "", $newFilename);
				$newFilename = str_replace(" ", "", $newFilename);
				$newFilename = $newFilename.'.'.$ext;
				$newPath = $image_dir[$i].strtolower($newFilename);
				if (file_exists($newPath)) { unlink($newPath); }
				rename($image_path[$i], $newPath);
				$i++;
			}


		}
?>

 

Thanks In Advance

- Clown

Link to comment
Share on other sites

I'm just gonna continue in this thread.... I've tried what you suggested thorpe... but for some weird reason I get this message:

 

Fatal error: Call to undefined function imagecreatetruecolor() in G:\www\dassrevyen\V2\includes\functions\diverse.php on line 141

 

this is the code I'm using..

<?php
function resizeImage($image)
{

	$imgSize = getimagesize($image);
	$imgWidth = $imgSize[0];
	$imgHeight = $imgSize[1];
	$percent = 0.5;
	$newWidth = "60";
	$newHeight = "60";

	$thumb = imagecreatetruecolor($newWidth, $newHeight);
	$source = imagecreatefromjpeg($image);

	imagecopyresized($thumb, $source, 0, 0, 0, 0, $newWidth, $newHeight, $imgWidth, $imgheight);
	imagejpeg($thumb);

}
?>

 

and about what you said about not using the while() loop... what you mean is that I upload the one file to the images folder and then use the imagecopyresized to add the thumbnail to the thumbs folder... did I understand that part right?

 

Thanks In Advance

- Clown

Link to comment
Share on other sites

yeah I know... I figured that out earlier in this thread... now I'm trying to resize...

 

gonna make a thumbnail version of the uploaded file now... and I basicly ripped off the example code from the link thorpe gave me... and it sais that the function imagecreatetruecolor() is undefined... I really don't udnerstand why it's doing that since it's a php function...

Link to comment
Share on other sites

review attached script

 

run resizeimage.php

 

and give 766 write to uploadedfiles folder

 

This is coping original size image to uploadedfiles folder first, then making resize it and store in same folder and deleting original size image.

 

[attachment deleted by admin]

Link to comment
Share on other sites

it returned this

 

Warning: Missing argument 1 for ImageResizeJpeg::getResizedImage(), called in G:\www\ir2_1\ir2_1\resizeimage.php on line 48 and defined in G:\www\ir2_1\ir2_1\ImageResizeClass.php on line 93

 

Fatal error: Call to undefined function imagecreatefromjpeg() in G:\www\ir2_1\ir2_1\ImageResizeClass.php on line 95

 

might it be that I'm testing my scripts trough my wamp server?

 

----

EDIT: I just tried uploading it on the server and still got some errors...

Warning: Missing argument 1 for getresizedimage() in /home/vhosts3/d/a/dassrevyen.no/www/test/ImageResizeClass.php on line 93

 

Warning: Cannot modify header information - headers already sent by (output started at /home/vhosts3/d/a/dassrevyen.no/www/test/ImageResizeClass.php:93) in /home/vhosts3/d/a/dassrevyen.no/www/test/resizeimage.php on line 51

Link to comment
Share on other sites

i just uploaded my own script to the server... and it's my resize part that's messing up...

 

resize function

<?php
function resizeImage($image)
{

	$imgSize = getimagesize($image);
	$file = pathinfo($image);
	$filename = $file['basename'];
	$location = "images/uploads/members/thumbs/".$filename;
	$imgWidth = $imgSize[0];
	$imgHeight = $imgSize[1];
	$newWidth = "60";
	$newHeight = "60";

	$source = imagecreatefromjpeg($image);
	$thumb = imagecreate($newWidth, $newHeight);

	imagecopyresized($thumb, $source, 0, 0, 0, 0, $newWidth, $newHeight, $imgWidth, $imgheight);
	imagejpeg($thumb);

}
?>

 

this is what happened

Warning: imagecopyresized() [function.imagecopyresized]: Invalid image dimensions in /home/vhosts3/d/a/dassrevyen.no/www/beta/includes/functions/diverse.php on line 146

ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC $.' ",#(7),01444'

 

=82<.342ÿÛC 2!!

ÿÀ<<"ÿÄ ÿĵ

 

hehe :D i want to resize down to 60x60 px

 

----

I've fixed the gd library suport now, so now it returns the same error locally as it does on the server

Link to comment
Share on other sites

yeah i'm sitting reading trough the files you sent me... thanks btw... but with all those classes I'm lost :) never worked with it before...hehe... but som reading, failing, fixing and getting more errors I'm sure I'll fix it eventually..

 

thanks for the help

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.