NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Website Development
Reload this Page Let People Upload Files To My Web Site

Website Development Development concepts, scripts, sponsors and affiliate programs.

Advanced Search
1 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 12-12-2004, 06:03 AM THREAD STARTER               #1 (permalink)
New Member
Join Date: May 2004
Posts: 7
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.
vector_anomaly is offline  
Old 12-12-2004, 07:18 AM   #2 (permalink)
NamePros Regular
 
Nunim's Avatar
Join Date: Oct 2004
Location: Florida
Posts: 384
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) {
????: NamePros.com http://www.namepros.com/website-development/59439-let-people-upload-files-my-web.html

    
$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;
????: NamePros.com http://www.namepros.com/showthread.php?t=59439
    
$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  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 11:07 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger