[advanced search]
NamePros Domain Auction
Live Event This Thursday at 6PM EST - Prebidding open now
8 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Domain Name Industry Newsletter
Go Back   NamePros.Com > Design and Development > Website Development
User Name
Password

Old 12-12-2004, 07:03 AM   · #1
vector_anomaly
New Member
 
Trader Rating: (0)
Join Date: May 2004
Posts: 7
NP$: 10.00 (Donate)
vector_anomaly is an unknown quantity at this point
Let People Upload Files To My Web Site

Hello,
I am trying to find out how I would beable to allow people to upload files to my web site. I would want to put a cap on file size.
Anyone know how I can do this thanks.


Please register or log-in into NamePros to hide ads
vector_anomaly is offline   Reply With Quote
Old 12-12-2004, 08:18 AM   · #2
Nunim
NamePros Regular
 
Nunim's Avatar
 
Location: Florida
Trader Rating: (2)
Join Date: Oct 2004
Posts: 385
NP$: 6.20 (Donate)
Nunim is an unknown quantity at this point
I wrote this for images but it can be very easily be modified for other files, install is easy just CHMOD to 777 and its set. Specify a few variables are your golden.... If you need help just ask.

PHP Code:
<?php

$site_name
= $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$upload_dir = "upload_files/";
$upload_url = $url_dir."/upload_files/";
$message ="";

//create upload_files directory if not exist
//If it does not work, create on your own and change permission.
if (!is_dir("upload_files")) {
    die (
"upload_files directory doesn't exist");
}

if (
$_FILES['userfile']) {
    
$message = do_upload($upload_dir, $upload_url);
}
else {
    
$message = "Invalid File Specified.";
}

print
$message;

function
do_upload($upload_dir, $upload_url) {

    
$temp_name = $_FILES['userfile']['tmp_name'];
    
$file_name = $_FILES['userfile']['name'];
    
$file_type = $_FILES['userfile']['type'];
    
$file_size = $_FILES['userfile']['size'];
    
$result    = $_FILES['userfile']['error'];
    
$file_url  = $upload_url.$file_name;
    
$file_path = $upload_dir.$file_name;

    
//File Name Check
    
if ( $file_name =="") {
        
$message = "Invalid File Name Specified";
        return
$message;
    }
    
//File Size Check
    
else if ( $file_size > 500000) {
        
$message = "The file size is over 500K.";
        return
$message;
    }
    
//File Type Check
    
else if ( $file_type == "text/plain" ) {
        
$message = "Sorry, You cannot upload any script file" ;
        return
$message;
    }

    
$result  =  move_uploaded_file($temp_name, $file_path);
    
$message = ($result)?"File url <a href=$file_url>$file_url</a>" :
              
"Somthing is wrong with uploading a file.";

    return
$message;
}
?>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
  Upload Image<input type="file" id="userfile" name="userfile">
  <input type="submit" name="upload" value="Upload">
</form>
Nunim is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
Website Header Design Website Header Design Website Header Design
Advertise your business at NamePros
All times are GMT -7. The time now is 03:05 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0