FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Upload Script





moejoe
Hey Guys.

I want to make a Simple upload script that'll upload files such as
.gif,.jpg,.mpg,.mp4,.3gp,.midi,.mp3,.aac

That'll go straight to my email as an attached file. ' Laughing

Thanks for your help! Smile
openaasman
you could specify attachement details in the header parameter of mail function.

for more clarity you could go to php manual site.
moejoe
Yer. Laughing
I look around at Hot-script and found that making an upload file wasn't as difficult as i though it was to be.
I could never get it attached to the email, but i got a notification email once someone uploaded something, so thats ok.

Thanks for your help.
NG
Well if any one wants a pretty simple upload script here it is Enjoy Very Happy

Step 1 Add this form in between your <body></body> tags:

Code:
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
Select a file <input type="file" name="userfile"><br>
<input type="submit" value="Upload!">


Step 2 Open a new file and copy the below code and save it as upload.php


Code:
<?php

if(!(copy($_FILES['userfile']['tmp_name'], "Upload/" . $_FILES['userfile']['name']))) die("Cannot upload files.");

echo "Upload Complete!";

?>




And now you should be done!

Basicly limiting MIME is quite easy.

Shown here:
Code:
switch ($_FILES[$this->field_name]["type"]) {
case 'application/octet-stream':
default:
// Unfamiliar extension (includes fla) must find
extension otherwise
$file_array = explode('.', $this->file_name);
$this->extension = end($file_array);
break;

case 'application/x-shockwave-flash';
$this->extension = 'swf';
break;

case 'application/postscript';
// Should be ai ps or eps
$file_array = explode('.', $this->file_name);
$this->extension = $file_array[1];
break;

case 'image/gif':
$this->extension = 'gif';
break;

case 'image/jpeg':
case 'image/pjpeg':
$this->extension = 'jpg';
break;

case 'image/x-png':
$this->extension = 'png';
break;

case 'image/psd':
$this->extension = 'psd';
break;

case 'image/bmp':
$this->extension = 'bmp';
break;
}


Might be a bit messed up, but still. Just incorperate that into the upload.php file. And that should work.

Also i've seen some questions on how to change the directory, or it dosent work for you.

Answer:
if(!(copy($_FILES['userfile']['tmp_name'], "Upload/" .
Changeing "Upload/" to another file will also work. But if the directory in which you upload these file's dosent have the "Upload/" directory then this whole script will not work!

Hope that helped!
NG
did this work?
Ghost Face
Hmm, I'm trying it on my site but I can't get it to work. I'm really new to Php so bear with me..

I'm trying to make it to where you don't have to be logged in or anything.

Help?
Related topics
looking for wap upload script
Upload Script
quite simple file upload
php upload issue
Upload a preset file using PHP
I need a php upload script, NEEDED BADLY
Mail attachment script???
File upload problem :'(
Upload Script
image upload, and return url to image
Upload Script
[RESOLVED] phpbb Help with making an upload script.
www.imagegarage.net
How to do an upload script??
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.