Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

Code for file upload in PHP

 
webmaster forum
arsah  Offline
Activity
0%
 
New Poster
Posts: 2
Topics: 2
February 19, 2010, 11:41:54 PM

Here I am giving you a sample code for uploading a file through PHP code. This is simple functionality that require you to create two files and place the ode given below in those files.

Hope this will help you all.

File 1: Upload form

Code:
<html>
<head>
     <title>Upload Form</title>
</head>
<body>
<form action="UploadSingle. php" method="post" enctype="multipart/form-data">
    Upload a file: <input type="file" name="thefile"><br><br>
    <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>


<!--
<?php
    $aErrors 
"";
    if ( !empty( 
$thefile_name ) ) // no file selected
    
{
        if ( ( 
$thefile_type == "image/gif" ) ||
             ( 
$thefile_type == "image/pjpeg" ) ||
             ( 
$thefile_type == "image/jpeg" ) ){
            if ( 
$thefile_size < ( 1024 100 ) ){
                
$aCurBasePath dirname$PATH_TRANSLATED );
                
$aNewName $aCurBasePath .  $thefile_name;
                
copy$thefile$aNewName );
            } else {
                
$aErrors . = "The file was too big";
            }
        } else {
            
$aErrors . = "The file was neither a gif nor a jpeg";
        }
    } else{
        
$aErrors . = "No file was selected";
    }
?>




File 2: Display file


Code:

<html>
<head>
     <title>Display an Uploaded Image</title>
</head>
<body>
<?php
    
if ( $aErrors != "" ){
        print( 
"<b>There were errors</b>: $aErrors<br>" );
    } else {
        print( 
"The picture you uploaded:<br><br>" );
        print( 
"<img src=\"/$thefile_name\" border=\"0\">" );
    }
?>

</body>
</html>

« Last Edit: August 25, 2011, 07:27:07 PM by Admin »
 
webmaster forum
Admin  Offline
*
 
Code Guru
Location: India
Gender: Male
Posts: 1387
Topics: 105
NaviBuster NaviBuster
WWW
February 20, 2010, 08:41:52 AM

Thanks for sharing this code with us all.
 
webmaster forum
CoderSquare.net Founder
Activity
0%
 
New Poster
Posts: 6
Topics: 1
WWW
April 27, 2010, 12:31:37 PM

Yeah this is definitely a useful tidbit.
 
webmaster forum
Life Is Good!
Activity
0%
 
Professional Coder
Gender: Female
Posts: 242
Topics: 3
WWW
April 11, 2011, 07:15:41 AM

thanks for this code.. this is helpful..

Affordable Custom Web Design Services
 
webmaster forum
eminent  Offline
Activity
0%
 
New Poster
Posts: 5
Topics: 1
June 11, 2011, 08:25:31 AM

you know wat tanks for that code
 
webmaster forum
grbrains  Offline
Open Source Development
Activity
0%
 
New Poster
Real name: GR Brains
Posts: 2
Topics: 1
WWW
June 18, 2011, 12:51:48 AM

Thanks for sharing code. .
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page January 25, 2012, 06:47:06 PM