Desperate - need help with image uploading/resizing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Noobie
Forum Commoner
Posts: 85
Joined: Sun May 15, 2005 11:38 am

Desperate - need help with image uploading/resizing

Post by Noobie »

Hi

I was hoping you could let me know in general terms the best way to achieve what I want.

I currently have a div with various bits of text generated from a table. This text is fed into the table via a form and it works nicely.

I now need to include an image in each of these divs to correspond with the particular bit of text and the image needs to be resized to a reasonable thumb size.

I'm unsure if it's possible to include the image upload (like this one: viewtopic.php?t=41743) within the same form that updates the table with the text content or whether I'll need to create a separate form entirely. If a separate form is required then how would I ensure the image is attached to the correct table entry?

Many thanks in advance.
Last edited by Noobie on Fri Apr 28, 2006 7:45 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Any number of file upload fields can be included in existing forms.
Noobie
Forum Commoner
Posts: 85
Joined: Sun May 15, 2005 11:38 am

Post by Noobie »

Ah great, that makes life a lot easier!

I suppose then I'd just include

Code: Select all

enctype="multipart/form-data"
in the form tag and add in the extra input box as per that tutorial?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try it.

I don't see a compelling reason this is in Databases, so moved to PHP - Code until further notice.
Noobie
Forum Commoner
Posts: 85
Joined: Sun May 15, 2005 11:38 am

Post by Noobie »

Sorry chaps - could I ask for help again?

I've been playing with this for a few days now with no luck whatsoever and my time is rapidly running out (like tomorrow).

My uploading form:

Code: Select all

<form enctype="multipart/form-data"  action="addoffer.php" method="post">
   <input type="hidden" name="id" value="NULL" />
   <label for="name">Enter the Company Name</label><br />
   <input type="text" name="name" title="input name" id="name" size="20" /><br />
   <label for="photo">Upload Photo</label> <input type="file" name="photo" size="20"><br />
   <label for="text">Enter Offer Details:</label><br />
   <textarea name="text" id="text" rows="5" cols="50"></textarea><br />
   <input type="submit" value="Submit Info" />
</form>
The addoffer.php page is:

Code: Select all

<?php
$dbh=mysql_connect ("localhost", "USERNAME", "PASSWORD") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("TABLENAME");
   
//making variables
$id = $_POST['id'];
$name = $_POST['name'];
$text = $_POST['text'];
$photo = $_POST['photo'];
	   
// the query
$result=MYSQL_QUERY("INSERT INTO TABLENAME (id,name,photo,text)".
"VALUES ('NULL', '$name', '$photo', '$text')");

//confirm
echo "The entry has been added to the Sponsors Details. <p><a href=\"admin.html\">Back to the Admin Page</a></p>";

?>
I just can't get my head around how to integrate the type of upload and thumb resizing that appears in the previously mentioned tutorial into what I already have. :oops:

Thank you in advance.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the uploaded file information will be in $_FILES['photo'] not $_POST['photo'].
Noobie
Forum Commoner
Posts: 85
Joined: Sun May 15, 2005 11:38 am

Desperate - need help with image uploading/resizing

Post by Noobie »

Obviously I'm really thick but I still can't get what I need. I can upload the image to the db (at least the blob field says it has a 5k file in it) but this isn't the "right way" to deal with images in a db is it? I can upload and resize an image as per that tutorial. What I can't achieve is combining those two steps.

I need to be able to upload and resize an image with the filename (presumably this is better) stored in the db along with the file name etc (all the text fields are already in place and working fine).

I need to be able to call the image along with the text on a page.

I need to be able to delete the row if necessary and get rid of the thumbnail wherever that's stored.

If I can't get anyone to help me then I'm willing to pay for someone to do this for me - PM me if you are interested.
Post Reply