473,386 Members | 2,050 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,386 software developers and data experts.

How to save a url dynamically into a database.

348 100+
Hello all..

Can someone recommend a tutorial on how to go about uploading a file (Image) and saving the url to the database? It would be great if the script could name the file also.

There should be no user intervention in saving the url to the database and should happen by way of the script. I will have a directory on the filesystem for the images. So basically, a script that would allow me to upload an image then place that image into an upload directory; take the name of that url and save it into the db.

I have searched the net and can only come up with hundreds of tutorials on how to stick an image into a db.. That isn't what I'm looking for. I want to put the url into the db then draw it out into a img tag to populate a page.

Thanks!

Frank
Jul 2 '07 #1
6 2831
fjm
348 100+
Hello again.. I was able to find a good tutorial on what I was looking for so I don't need help per say with the image upload anymore but I could sure use a little clarification on OOP.

Can someone who really understands OOP tell me if I can take a piece of code and put it into a class instead of sticking this code into my html?

Here a piece of that script:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. error_reporting(E_ALL);
  3. if(isset($_GET['id']))
  4. {
  5. include 'library/config.php';
  6. include 'library/opendb.php';
  7. $id     = $_GET['id'];
  8. $query = "SELECT name, type, size, path FROM upload2 WHERE id = '$id'";
  9. $result = mysql_query($query) or die('Error, query failed');
  10. list($name, $type, $size, $filePath) = mysql_fetch_array($result);
  11. header("Content-Disposition: attachment; filename=$name");
  12. header("Content-length: $size");
  13. header("Content-type: $type");
  14.  
  15. readfile($filePath);
  16. include 'library/closedb.php'; 
  17. exit;
  18. }
  19. ?>
Can I use this piece of code in a constructor and call it from the class I make?

I am trying to learn OOP and while the concept is brutally easy, putting it into practice is a different story for me. :)

Thanks guys!

Frank
Jul 2 '07 #2
pbmods
5,821 Expert 4TB
Heya, Frank.

The basic idea behind OOP is to stop thinking in terms of tasks, and to start thinking in terms of objects.

For example, when uploading a file to the database, you'll be working with:
  • An upload (which is also a file)
  • A database connection

To implement this, you're going to want to create three classes:

Expand|Select|Wrap|Line Numbers
  1. class File {
  2.     protected $myPath;
  3.  
  4.     public function __construct($path) {
  5.         $this->myPath = $path;
  6.     }
  7.  
  8.     public function __toString() {
  9.         return $this->myPath;
  10.     }
  11. }
  12.  
  13. class Upload extends File {
  14.     protected $myMeta;
  15.  
  16.     public function __construct($index) {
  17.         $this->myMeta = $_FILES[$index];
  18.         parent::__construct($this->myMeta['tmp_name']);
  19.     }
  20. }
  21.  
For info on how to set up the Database class, check out this article.

This is a very basic example. You'll need to create member functions that process your uploads, since otherwise PHP will delete them.

For more information, check out this page.

Ask questions.
Jul 2 '07 #3
kovik
1,044 Expert 1GB
This may also be of interest.

Understanding Object-Oriented Programming
Jul 2 '07 #4
fjm
348 100+
Thank you guys! I will read the links you provided..


Frank
Jul 2 '07 #5
fjm
348 100+
This may also be of interest.

Understanding Object-Oriented Programming
Hey volectricity,

Nice site you got there! I bet the visually impared love it. :)

Seriously though. You did a great job on that! Also, thank you for a terriffic OOP article.. I am on my way now!!

Thanks again,
Frank
Jul 2 '07 #6
@fjm
Frank,
Where was that tutorial you mentioned. I am trying to accomplish the same thing in a current program I am developing but having a devil of a time trying to get my brain wrapped around it.

PB
Jun 7 '10 #7

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

Similar topics

10
by: Martin Dale | last post by:
Dear all, Is there any way to activate the Save As command from Javascript. I would like to have a "Save as" button on a page which has been dynamically created (client side using...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
0
by: Sky | last post by:
Hello: HUGE question that has blocked me for a while now: I have a usercontrol called Module_PhoneList that is injected in a Panel , which can show up in different Pages. (Basically a portal)....
2
by: djc | last post by:
On the page_load event I am querying a database and binding data to some text boxes, list boxes, and a repeater control. When the page loads it uses the value of one of the database fields (status)...
3
by: MJ | last post by:
Automatically download and save pdf files from a website. Is there a way to do this? I would like to automate a daily procedure for downloading and saving a couple of dozen pdf from several...
4
by: jesper_lofgren | last post by:
Hi there, I have some webcontrols that i want to add dynamically on a page. I have stored the path / namespace in database (ex MyNameSpace.WebControls.Control1) to the class/webcontrol. Lets...
5
by: \A_Michigan_User\ | last post by:
I'm using asp.net/vb.net/ado.net to create a very simple user interface. (Everything works if I use STATICALLY created textBoxes... but not when I make them DYNAMICALLY.) 1. Execute a SQL...
1
by: Iain | last post by:
Hi All I have a datagrid - buit dynamically from a database table - which contains a column with links to many documents. When the user selects a link I want them to be able to open the document...
5
by: aashishn86 | last post by:
hi i am using this code for adding /deleting rows dynamically : function addRow() { var tbl = document.getElementById('applications'); var lastRow = tbl.rows.length; // if there's no...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.