File uploading

 
<?
    
// ASP-style tags are okay in PHP 3.0.4 and above; some HTML editors recognize these tags

    // File Upload Script for PHP/3 for Windows

    // Released under the terms of the public GNU license
    // Based upon code written by Rasmus Lerdorf
    // Modified for Windows by Michael Grier
    // E-mail: bigmike@bigmweb.com

    // You need to write-enable a directory, named "upload", below the one you place this script in
    // On Windows NT, you can do this with a DOS program named CACLS
    // Directions for this can be found at "http://www.bigmweb.com/home/cacls.html"



if($action1){                                                    // if
files have been uploaded, process them

?>
    <html>
    <head>
    <title>File Upload Results</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#FFFFFF" text="#000000">
    <p><font face="Arial, Helvetica, sans-serif"><font size="+1">File
Upload Results</font><br><br>

<?
    set_time_limit
(60);                                           // make
reasonably sure the script does not time out on large files
    $path1
= dirname($PATH_TRANSLATED)."/upload/";                // assign
our path in a form PHP for Windows understands

             $source
= $file1;
             
$source_name = $file1_name;

       if((
$source <> "none")&&($source <> "")){                  // see if
the file exists; non-existing file has name of "none"
          
if($error1 <> 1){                                       // no
need to copy a file if directory not write-enabled
             $dest
= $path1.$source_name;                         // append
file name to our path
             
if(copy($source,$dest)){                             // copy
the file from the temp directory to the upload directory, and test for success
                
echo "$source has been uploaded<br>/n";
                
$imagesize = getimagesize($dest);

                switch(
$imagesize[2])  {
                         case
0:
                            echo
"<br> Image is a unknown <br>";
                            
unlink($dest);
                            exit;
                         case
1:
                            echo
"<br> Image is a GIF <br>";
                            echo
"$dest has a width of $imagesize[0]<br>";
                            echo
"$dest has a height of $imagesize[1]<br>";
                            
$newname = $path1;
                            
$newname .=time() . ".gif";
                            if(
copy($dest,$newname)) {
                            echo
"<br> GIF Rename Successful from $dest to
$newname"
;
                            }
                            else {
                            echo
"<br> GIF Rename Unsuccessful";
                            }
                            
unlink ($dest);
                            break;
                         case
2:
                            echo
"<br> Image is a JPG <br>";
                            echo
"$dest has a width of $imagesize[0]<br>";
                            echo
"$dest has a height of $imagesize[1]<br>";
                            
$newname = $path1;
                            
$newname .=time() . ".jpg";
                            if(
copy($dest,$newname)) {
                            echo
"<br> JPG Rename Successful from $dest to
$newname"
;
                            }
                            else {
                            echo
"<br> JPG Rename Unsuccessful";
                            }
                            
unlink ($dest);
                            break;
                         case
3:
                            echo
"<br> Image is a PNG <br>";
                            echo
"$dest has a width of $imagesize[0]<br>";
                            echo
"$dest has a height of $imagesize[1]<br>";
                            
$newname = $path1;
                            
$newname .=time() . ".png";
                            if(
copy($dest,$newname)) {
                            echo
"<br> PNG Rename Successful from $dest to
$newname"
;
                            }
                            else {
                            echo
"<br> PNG Rename Unsuccessful";
                            }
                            
unlink ($dest);
                            break;
                         }
                  }
             else {
                echo
"Upload directory not write-enabled/n";      // you
need to write-enable the upload directory
                $error1
= 1;                                      // set flag
             
}
          }
          
unlink($source);                                        // delete
the file from the temp directory
       
}

?>

    <br><a href="upload.php3">Back</a>
    </font></p>
    </body>
    </html>

<?
}
else {

?>

    <html>
    <head>
    <title>File Upload</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#FFFFFF" text="#000000">
    <p><font face="Arial, Helvetica, sans-serif"><font size="+1">File
Upload</font><br><br>
    If your browser is upload-enabled, you will see &quot;Browse&quot;
(Netscape, Internet Explorer) or &quot;. . .&quot; (Opera) buttons below.
Use them to select file(s) to upload, then click the &quot;Upload&quot;
button. After the files have been uploaded, you will see a results screen.<br>
    <form method="post" enctype="multipart/form-data" action="upload.php3">
            <input type="hidden" name="MAX_FILE_SIZE" value="800000">
            <input type="hidden" name="action1" value="1">
    File 1: <input type="file" name="file1" size="30"><br>
    <br>
            <input type="submit" value="Upload">
    </form>
    </font></p>
    </body>
    </html>

<?

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值