It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

Show upload files in my browser

Moderator: Malcolm

Show upload files in my browser

Postby jeaddy on Sun Feb 10, 2008 1:50 am

Hello everyone,

I have a question with upload files. I create a html form and php codes to upload files. I also created a directory called uploads where my php upload files resides. when I upload it, all the files goes to the uploads directory.

so my question is when I upload can it be save into mysql and then I can bring it out and show it in the browser instead of how i have it in the directory.

How would I do this? I really want to show what I upload in the browser/server.

thanks -
jeaddy
 
Posts: 24
Joined: Thu Dec 20, 2007 12:35 am

Postby leonard on Mon Feb 11, 2008 1:46 pm

You can store files in the database using the blob datatype (blob = binary large object).

Code: Select all
DROP TABLE IF EXISTS `pics`;
create table pics(
   PIC_ID     int(5) not null auto_increment,
   PICNAME    varchar(100),
   PICTURE    blob
) TYPE=INNODB;


You can insert and select the data using:
Code: Select all
insert into picture (PIC_ID,PICNAME,PICTURE)
values ($PIC_ID,$PICNAME,load_file("/mypath/mypicture");

select PICTURE from picture where PIC_ID = $PIC_ID;

Note that displaying the picture needs more than simply selecting it. It always depends on what you want to store.

cheers!
- leonard
:%s/^M//
There are 10 kinds of people:
Those who understand binary and those who don't.
User avatar
leonard
100+ Club
 
Posts: 147
Joined: Tue Dec 18, 2007 7:11 am
Location: Switzerland

Postby flabbyrabbit on Mon Feb 11, 2008 9:12 pm

If you are simply uploading the image to your server, then you could do as leonard said, but change "PICTURE blob " to "PICLINK varchar(100)". Then you could simply echo out the picture using the link in the database.
Code: Select all
<?php
echo "<img src='".$row[PICLINK]."'>";
?>


Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby jeaddy on Tue Feb 12, 2008 12:04 am

Kool, thanks leonard and flabbyrabbit.



It always depends on what you want to store


I want to store mostly picture, excel files and sometimes music.

so do you think those are all possible?

thanks
jeaddy
 
Posts: 24
Joined: Thu Dec 20, 2007 12:35 am

Postby flabbyrabbit on Tue Feb 12, 2008 12:10 pm

Do you just want to show links to the files? Then my way would work. If you created a mysql database with: name and url. Then you could add some code to the upload form which adds the new file to the database. Then when someone views the directory you could echo out the files quite easily.

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby jeaddy on Wed Feb 13, 2008 3:15 am

Do you just want to show links to the files?

I want to show the files in the browser, the image of it. I created one and it works but it doesn't work for all pictures, it doesn't show all pictures only some. Do you know why that is?

I also would like to upload music and ms doc (mostly excel) files, so how would I select these and view them on the browser?

thanks
jeaddy
 
Posts: 24
Joined: Thu Dec 20, 2007 12:35 am

Postby jeaddy on Thu Feb 14, 2008 1:02 am

Hi

I just noticed why some pictures can't be uploaded, because some of those pictures files size are too large, about 600kb or 1.2 mb. I currently can only upload about 17 kb, how can I increase this capacity so that I can upload all my pictures?


thanks
jeaddy
 
Posts: 24
Joined: Thu Dec 20, 2007 12:35 am

Postby leonard on Thu Feb 14, 2008 7:59 am

I currently can only upload about 17 kb

You need to change your php-configuration.

Edit these values in your php.ini file and then restart the webserver:
upload_max_filesize = 5M ;
post_max_size = 6M ;

upload_max_filesize is the maximum a single file can be.
post_max_size is the total limit of your post.

cheers!
- leonard
:%s/^M//
There are 10 kinds of people:
Those who understand binary and those who don't.
User avatar
leonard
100+ Club
 
Posts: 147
Joined: Tue Dec 18, 2007 7:11 am
Location: Switzerland

Postby jeaddy on Thu Feb 14, 2008 11:28 pm

Thanks
jeaddy
 
Posts: 24
Joined: Thu Dec 20, 2007 12:35 am

Postby jeaddy on Thu Feb 14, 2008 11:51 pm

You know how I can upload excel (ms docs) files and musics files into a database and show it?



Thanks
jeaddy
 
Posts: 24
Joined: Thu Dec 20, 2007 12:35 am

Next

Who is online

Users browsing this forum: No registered users and 1 guest