Page 1 of 1

Desperate - need help with image uploading/resizing

Posted: Fri Apr 21, 2006 8:00 am
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.

Posted: Fri Apr 21, 2006 8:30 am
by feyd
Any number of file upload fields can be included in existing forms.

Posted: Fri Apr 21, 2006 8:50 am
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?

Posted: Fri Apr 21, 2006 8:53 am
by feyd
try it.

I don't see a compelling reason this is in Databases, so moved to PHP - Code until further notice.

Posted: Thu Apr 27, 2006 12:01 pm
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.

Posted: Thu Apr 27, 2006 4:43 pm
by feyd
the uploaded file information will be in $_FILES['photo'] not $_POST['photo'].

Desperate - need help with image uploading/resizing

Posted: Fri Apr 28, 2006 7:45 am
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.