473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Resize and Save an image in PHP4

I have been working on a script that uploads an image to a server and add a reference to that Image in a database.
The server runs a PHP4 version on apache ( and there is no chance to upgrade )
So I wanna modify the following upload script to resize the image automatically

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.                           include_once('CheckLogin.php');
  3.                           include_once('LoginLogoutLink.php');
  4.                           ?>
  5.  
  6.                           </td>
  7.                         </tr>
  8.                         <tr>
  9.                           <td>
  10.                             <?php
  11.  
  12. include_once('db_con.php');
  13. $feedback = '';
  14. if(isset($_POST['UploadImage']))
  15. {
  16.  
  17. $result = '';
  18. $query = '';
  19. $un = $_SESSION['username'];
  20. $imageURL= $_POST['imageURL'];
  21. $ct = $_POST['categorylist'];
  22. $photo = '';
  23.  
  24. $MemberName = $_POST['MemberName'];
  25. $Title = $_POST['Title'];
  26. $Bike = $_POST['Bike'];
  27. $EventName = $_POST['EventName'];
  28. $Date = $_POST['Date'];
  29. $ClubName = $_POST['ClubName'];
  30. $Location = $_POST['Location'];
  31.     if(isset($_FILES['userfile']['name']) && $_FILES['userfile']['name'] != "")
  32.         {
  33.             $size = getimagesize($_FILES['userfile']['tmp_name']);
  34.             $w = $size[0];
  35.             $h = $size[1];          
  36.  
  37.                 $uploaddir = 'allimages/';              
  38.                 $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
  39.  
  40.  
  41.                 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
  42.                 {
  43.                     chmod($uploadfile,0755);
  44.                     $photo = $uploadfile;                   
  45.                     $query = "insert into userpictures
  46.                             (category,uploadpicname,imageURL,MemberName,Title,Bike,EventName,Date,ClubName,location) 
  47.                             values ('$ct','$photo','$imageURL','$MemberName','$Title','$Bike','$EventName','$Date','$ClubName','$Location') ";
  48.  
  49.                     $result = mysql_query($query);
  50.  
  51.                     if($result)
  52.                     {
  53.                         $feedback = 'Image Uploaded Successfully';              
  54.                     }
  55.                     else
  56.                     {
  57.                         die('Database Error');
  58.                     }
  59.                 }
  60.                 else
  61.                 {
  62.                     $feedback = 'Uploaded Image Is Not Valid!';                     
  63.                 }
  64.  
  65.         }
  66.         else
  67.         {
  68.             $feedback = 'Please Select Image!';
  69.         }
  70.  
  71. }
  72. ?>
  73.  
Jan 29 '10 #1
1 2618
dgreenhouse
250 Expert 100+
Maybe this will point you in the right direction:
http://www.white-hat-web-design.co.u...e-resizing.php

You'll have to have php4.3 or above and the gd extension loaded...
Jan 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Paul Jaeger | last post by:
I have jpeg images that are 2848 x 4256 pixels. I want to programatically convert them to images that are approximately 427 x 638 (that maintains the ratio) and save to new jpeg files. How can...
0
by: Jay | last post by:
Hi guys, trying to fix a problem with an image resize routine. The code posted below uploads and resizes a jpeg, probablem is, the outlook can look a bit bitty becuase of teh samller size...is...
1
by: John Scott | last post by:
I am storing an image in an SQL database and have one field as an image datatype. I am also using a webservice to transport data. I want to be able to resize the image and pass back a thumbnail...
0
by: funcSter | last post by:
I've got this bit of code: Image origImage = Image.FromFile("temp.jpg"); Image newImage = new Bitmap(objNewSize.Width, objNewSize.Height, origImage.Pixelformat); Graphics objGraphic =...
4
by: SlasherStanley | last post by:
BlankHi How do you resize a jpg file. I want to open a file (c:\abc.jpg 800 x 600) and resize it as 120 x 100, I then want to save it as c:\abc_t.jpg. Thanks Slasher
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
1
by: Arjen | last post by:
Hi, I want to resize an image on my server. I tried a lot of samples... but all the time it does resize and saves the images but I can not view the image insize a webbrowser. With an...
2
by: Dominic Vella | last post by:
Hi, I know I seem to have the really complicated questions, but I guess that's why I'm here. This is a little verbose, only because I've been trying to crack this for a week now. Your help...
3
by: Noorain | last post by:
Sir i want to resize image. Following script working in my local server. But This coding doesn't work in php 2.6.0. please help me <form action="<?php echo $_server; ?>" method="post"...
3
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi! This discussion may help other programmers get a better idea of how to save uploaded images through a website. Why? Well currently, I save 3 versions of every uploaded image on my own...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.