web directoryearn money in seconds   Free file hosting, free video sharing

<<< The Web Hosting >>>


Go Back   Noeman GSM > Webhosting & Website development > Website development > Programming

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-30-2007, 11:20 AM
Spiral's Avatar
CO-Admin
 
Join Date: Sep 2004
Location: Martil
Age: 25
Posts: 15,673
Reputation: 18872
Spiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super Member
Default Creat Simple Upload Page by PHP ( file sharing)

with this code, you can create an upload page that combines HTML and PHP easily.

Step 1 : Create one page with HTML content

HTML Code:
<html>  
<head>  
<title>Upload</title>  
</head>  
<body>  
<h1>Upload</h1>  
<form enctype="multipart/form-data" action="upload.php" method="post">  
<input type="hidden" name="MAX_FILE_SIZE" value="1000000"> File:  
<input name="userfile" type="file">  
<input type="submit" value="Upload">  
</form>  
</body>  
</html> 
Step 2 : Create file upload.php with content :

HTML Code:
<?php  
// $userfile is where file went on webserver  
$userfile = $HTTP_POST_FILES['userfile']['tmp_name'];  
// $userfile_name is original file name  
$userfile_name = $HTTP_POST_FILES['userfile']['name'];  
// $userfile_size is size in bytes  
$userfile_size = $HTTP_POST_FILES['userfile']['size'];  
// $userfile_type is mime type e.g. image/gif  
$userfile_type = $HTTP_POST_FILES['userfile']['type'];  
// $userfile_error is any error encountered  
$userfile_error = $HTTP_POST_FILES['userfile']['error'];  

// userfile_error was introduced at PHP 4.2.0  
// use this code with newer versions  

if ($userfile_error > 0) {  
echo 'Problem: ';  
switch ($userfile_error)  
{ case 1:  
echo 'File exceeded upload_max_filesize';  
break;  
case 2:  
echo 'File exceeded max_file_size';  
break;  
case 3:  
echo 'File only partially uploaded';  
break;  
case 4:  
echo 'No file uploaded';  
break;  
}  
exit;  
}  

// put the file where we'd like it  
$upfile = '/uploads/'.$userfile_name;  

// is_uploaded_file and move_uploaded_file  
if (is_uploaded_file($userfile))  
{  
if (!move_uploaded_file($userfile, $upfile))  
{  
echo 'Problem: Could not move file to destination directory';  
exit;  
}  
} else {  
echo 'Problem: Possible file upload attack. Filename: '.$userfile_name;  
exit;  
}  
echo 'File uploaded successfully<br /><br />';  

// show what was uploaded  
echo 'Preview of uploaded file contents:<br /><hr />';  
echo $contents;  
echo '<br /><hr />';  
?>
Note :line: $upfile = '/uploads/'.$userfile_name; Folder of files have been stored, you can change it depending on your ideas

--------------------------------------------------------------------------------

Another form of Upload file, you can choose file that you want to upload optionally

Create file upload.php with contents

HTML Code:
<?php  
  //Define some variables  
      $dir = "path/where/you/want/to/upload/files/"; //Bạn nên thay đổi đường dẫn cho phù hợp  
    //Kiều file, Gif, jpeg, zip ::bạn có thể sửa đổi nếu thích  
      $types = array("image/gif","image/pjpeg","application/x-zip-compressed");  
      
//Check to determine if the submit button has been pressed  
    if(isset($_POST['submit'])){  

//Shorten Variables  
     $tmp_name = $_FILES['upload']['tmp_name'];  
     $new_name = $_FILES['upload']['name'];  

//Check MIME Type  
    if (in_array($_FILES['upload']['type'], $types)){  
                     
         //Move file from tmp dir to new location  

        move_uploaded_file($tmp_name,$dir . $new_name);  
            
        echo "{$_FILES['upload']['name']} was uploaded sucessfully!";                                          
            
    }else{  
                 
    //Print Error Message  

     echo "<small>File <strong><em>{$_FILES['upload']['name']}</em></strong> Was Not Uploaded!</small><br />";  
       
    //Debug  
   $name =  $_FILES['upload']['name'];  
   $type =    $_FILES['upload']['type'];  
   $size =    $_FILES['upload']['size'];  
   $tmp =     $_FILES['upload']['name'];  
      
   echo "Name: $name<br/ >Type: $type<br />Size: $size<br />Tmp: $tmp";  
               
    }  
        
    }        
        
else{        
        
    echo 'Could Not Upload Files';  
        
}  
        ?>  
            
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">  
        
      <fieldset>  
              <legend>Upload Files</legend>  
                                            
          <input type="file" name="upload" />  
</fieldset>  
<input type="submit" name="submit" value="Upload Files" />  
</form>
You are done.Good luck
Reply With Quote
Sponsored Links
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:37 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
Copyright © 2004-2008 Noeman . All rights reserved
Industrial Directory | Credit Card Consolidation | Loan | Debt Consolidation | Bad Credit Mortgages

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111