Author Topic: File Upload within a form  (Read 2995 times)

adammcmillan

  • New Member
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
File Upload within a form
« on: April 01, 2008, 11:00:46 PM »
Is there a way to do a file upload (for a photo or PDF) within another form using PHP?
I'm trying to make a form that posts information to a database but I want to do a file upload to allow the user to upload a pdf to a column on the database as well.

Any insight?

Thanks.

peg110

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 799
  • Karma: +0/-0
    • View Profile
    • http://www.tripleclicks.com/11260983/go
Re: File Upload within a form
« Reply #1 on: April 02, 2008, 10:38:14 AM »
Quote from: "adammcmillan"
Is there a way to do a file upload (for a photo or PDF) within another form using PHP?
I'm trying to make a form that posts information to a database but I want to do a file upload to allow the user to upload a pdf to a column on the database as well.

Any insight?

Thanks.

Well if you want to "Upload" a file into your database, of course you need to make sure you have the correct data type (I believe it's blob).

But YES, you can use PHP and HTML to do file uploads.

A good place to start would be http://us.php.net/features.file-upload

adammcmillan

  • New Member
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: File Upload within a form
« Reply #2 on: April 02, 2008, 03:06:17 PM »
I know how to upload a file flat out....my question is can I upload a file with a form.
Here's the application.

I have a form where a user can insert information into a variety of fields that will be stored into a database and then printed in a table in another section of the website..kind of acting like a CMS. I want one of the columns in that table to be a link to a PDF (different for each record). Is that possible all within this one form??

peg110

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 799
  • Karma: +0/-0
    • View Profile
    • http://www.tripleclicks.com/11260983/go
Re: File Upload within a form
« Reply #3 on: April 09, 2008, 02:17:43 PM »
I not really sure what you are asking.

You want to upload the file on one page and display a link to the uploaded file on another?

When you talk FORM are you talking about an HTML Form (i.e. <form action="blahblah.php" method="POST"> .... ?) or are you talking about something different?

adammcmillan

  • New Member
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: File Upload within a form
« Reply #4 on: April 09, 2008, 02:22:30 PM »
I have made a PHP form that takes the user's input text and posts to the database. I have another page that is selecting all of those fields and displaying them in a table. But I want to add to that HTML form a file upload to upload a PHP document that will also be selected and printed in the calling page's table as a link.

Can I combine the file upload scripts within the original form?

peg110

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 799
  • Karma: +0/-0
    • View Profile
    • http://www.tripleclicks.com/11260983/go
Re: File Upload within a form
« Reply #5 on: April 09, 2008, 02:30:41 PM »
You should be able to, however, you will only be able to "Submit" one form at a time.

adammcmillan

  • New Member
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: File Upload within a form
« Reply #6 on: April 09, 2008, 02:48:13 PM »
Okay...yeah that's my question.

I was wondering in the processing script if I could upload and save the image (pdf) and process the form to the database within the same script.

peg110

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 799
  • Karma: +0/-0
    • View Profile
    • http://www.tripleclicks.com/11260983/go
Re: File Upload within a form
« Reply #7 on: April 10, 2008, 11:23:33 AM »
Yes, as long as both are done with the same form (Since that is the data that gets submitted). Obviously you would need to setup your script so that it processes everything you need (the upload as well as the database information.)

adammcmillan

  • New Member
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: File Upload within a form
« Reply #8 on: April 10, 2008, 11:41:24 AM »
gracias.