clown[NOR] Posted May 17, 2007 Share Posted May 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/ Share on other sites More sharing options...
trq Posted May 17, 2007 Share Posted May 17, 2007 move_uploaded_file does just that, moves the file. So when you go to move it again (second time through your loop) its not there to move. Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255067 Share on other sites More sharing options...
clown[NOR] Posted May 17, 2007 Author Share Posted May 17, 2007 ok...so what should I do then? copy() or something? don't even know if that exists but if it does... do i copy them after the while () I use unlink($_FILES['bilde']['tmp_name']) ??? Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255068 Share on other sites More sharing options...
trq Posted May 17, 2007 Share Posted May 17, 2007 Considering you also want to resize the image, Id'e use imagecopyresized to resize and copy the image to a new location. Now you don't even need the while() loop. Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255071 Share on other sites More sharing options...
clown[NOR] Posted May 17, 2007 Author Share Posted May 17, 2007 hmmm... i gotta read about that... I'll check back if I have any further questions thanks thorpe Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255073 Share on other sites More sharing options...
clown[NOR] Posted May 17, 2007 Author Share Posted May 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255077 Share on other sites More sharing options...
jitesh Posted May 17, 2007 Share Posted May 17, 2007 Try Copy() insted of move_uploaded_file(); Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255093 Share on other sites More sharing options...
clown[NOR] Posted May 17, 2007 Author Share Posted May 17, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255097 Share on other sites More sharing options...
jitesh Posted May 17, 2007 Share Posted May 17, 2007 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] Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255099 Share on other sites More sharing options...
clown[NOR] Posted May 17, 2007 Author Share Posted May 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255100 Share on other sites More sharing options...
jitesh Posted May 17, 2007 Share Posted May 17, 2007 Configure your php.ini with gd library support. First copy php_gd2.dll to c://windows (Whatever this is) folder Then in php.ini make change insted of ;extension=php_gd2.dll keep extension=php_gd2.dll Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255102 Share on other sites More sharing options...
clown[NOR] Posted May 17, 2007 Author Share Posted May 17, 2007 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 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 Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255104 Share on other sites More sharing options...
jitesh Posted May 17, 2007 Share Posted May 17, 2007 modified attachements. Try this at your server. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255105 Share on other sites More sharing options...
clown[NOR] Posted May 17, 2007 Author Share Posted May 17, 2007 now that worked... but my problem here is... how can I make that work with my script? I have a feeling that I'm almost there with my function... can you see what i've done wrong? Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255109 Share on other sites More sharing options...
clown[NOR] Posted May 17, 2007 Author Share Posted May 17, 2007 Well... haha... i fixed one problem and it turned out that by fixing that even more errors were waiting right around the corner... now I've got Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255113 Share on other sites More sharing options...
jitesh Posted May 17, 2007 Share Posted May 17, 2007 Comepare code for both. will approx same. That script supports gif and bmp too. Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255115 Share on other sites More sharing options...
clown[NOR] Posted May 17, 2007 Author Share Posted May 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51773-help-upload-same-image-to-2-directories/#findComment-255116 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.