Upload script

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
KikoLtd
Forum Newbie
Posts: 1
Joined: Mon Sep 01, 2008 6:14 am

Upload script

Post by KikoLtd »

Hi guys!
I am new both on forum and on php. I have created a website (an index page on html and an upload script on php). A user can select a file and then if he press the submit button, his file is uploaded in a folder. But many of my friends have asked me to give an embed code and a url of the file they have uploaded under the file (eg if he visit http://www.mysite.com/uploads/image1 they want to give them the embed code <img src="http://mysite.com/uploads/image1"> and the url http://www.mysite.com/uploads/image1 ). But only if it is an image. If it is a zipped file or a sound i want to show an icon, an embed code and a url. How can i do that? If you cannot give me a code please give me an idea, i'll try to create it on my own.
Ragards

PS
sorry for my bad english
Gevie
Forum Newbie
Posts: 5
Joined: Sun Aug 31, 2008 2:43 pm

Re: Upload script

Post by Gevie »

Easiest way to do this would be to store all your uploaded files into a database.
If not you can use something like this when the user uploads

$_FILES['file']['type']

or even easier find the extension of the file

Code: Select all

$file_ext = strrchr($_FILES['file']['name'], '.');
Then you could do something like

Code: Select all

 
if($file_ext == 'jpg' || $file_ext == 'jpeg') {
 // Code to display the embedded code here
}
 
Post Reply