<blockquote id="jgpii"><font id="jgpii"></font></blockquote>



    ENCTYPE=\"multipart\/form-data\"?METHOD=POST>


    NAME=\"MAX_FILE_SIZE\"?VALUE=\"2000000\">


    NAME=\"uploadfile\"?SIZE=\"24\"?MAXLENGTH=\"80\">






    NAME=\"sendit\">?


    NAME=\"cancelit\">


    <\/FORM>

    (You?may?notice?a?slight?

    delay?while?we?upload?your?file.)<\/FONT><\/I>

    <\/BODY>

    <\/HTML>



    下面是處理上傳的文件:

    (?receiver.php3?):


    function?do_upload?()?

    {

    global?$uploadfile,?$uploadfile_size;

    global?$local_file,?$error_msg;

    if?(?$uploadfile?==?\"none\"?)?

    {

    $error_msg?=?\"You?did?not?specify?a?file?for?uploading.\";

    return;

    }

    if?(?$uploadfile_size?>?2000000?)?

    {

    $error_msg?=?\"Sorry,?your?file?is?too?large.\";

    return;

    }

    $the_time?=?time?();

    \/\/?你需要對以下目錄有寫權(quán)限

    $upload_dir?=?\"\/local\/uploads\";

    $local_file?=?\"$upload_dir\/$the_time\";

    if?(?file_exists?(?'$local_file'?)?)?

    {

    $seq?=?1;

    while?(?file_exists?(?\"$upload_dir\/$the_time$seq\"?)?)?{?$seq++;?}

    $local_file?=?\"$upload_dir\/$the_time$seq\";

    };

    rename?(?$uploadfile,?$local_file?);

    display_page?();

    }

    function?display_page?()?

    {

    \/\/?這里是你的頁面內(nèi)容

    }





    php3?Receiving?Script<\/TITLE><br><br><\/HEAD><br><br><BODY> <h1><a href="http://www.miracleart.cn/">国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂</a></h1><br><br><??<br><br>if?(?$error_msg?)?{?echo?\"<B>$error_msg<\/B><BR><BR>\";?<br>}<br><br>if?(?$sendit?)?<br><br>{<br><br>do_upload?();<br><br>}?<br><br>elseif?(?$cancelit?)?<br><br>{<br><br>header?(?\"Location:?$some_other_script\"?);<br><br>exit;<br><br>}?<br><br>else?<br><br>{<br><br>some_other_func?();<br><br>}<br><br>?><br><br><\/BODY><br><br><\/HTML><br><br><br><br>5.5?常用函數(shù)<br><br><br><br>我們簡單來看看一些常用的函數(shù)。<br><br><br><br>Array<br><br><br><br><br><br>array - generate array <br><br>count - number of array elements <br> <br>sort - Array sorting, there are several other sorting functions available <br><br>list - List array elements <br><br>each - Return the next key\/value pair <br><br>current - Returns the current array element <br><br>next,prev - Returns the pointers before and after the current array element <br><br><br><br><br><br><br><br>Date and Time <br><br><br><br>checkdate - Verify date\/time format <br><br>date - Generate date\/time format <br><br>time - Current time information <br><br> strftime - Format date\/time <br><br><br><br>Directory, file system <br><br><br><br>chdir - Change directory <br><br>dir - Directory category <br><br>opendir, readdir, closedir - open, read, close the directory <br><br>fopen, fclose - open, close the file <br><br>fgets, fgetss - read the content line by line <br> <br>file - Read the entire file into an array variable <br><br><br><br>Regular expression <br><br><br><br>ereg - Match regular expression <br> <br>eregi - Matches regular expressions in case insensitive <br><br>ereg_replace - Matches regular expressions and replaces them <br><br>eregi_replace - Matches regular expressions in case insensitive cases and replaces them <br><br>split - Split the string according to the rules and store it in array form<br><br><br><br><br><br><br>String<br><br><br><br>AddSlashes - Use a string after adding a slash <br><br>echo - Output one or more strings <br><br>join, implode - Combine array elements into a string <br><br>htmlentities, htmlspecialchars - Convert HTML special characters into HTML tag form <br><br>split - Split the string according to rules and store it in array form <br><br>5.6 Extend our sample homepage <br><br><br> <br>We will use some of the functions and ideas mentioned above to add more dynamic content to our sample homepage. We can add a navigation bar at the top of each page, and at the same time make the current page automatically not displayed by links; we can also add a user verification form to upload music, images and other files and automatically update the page. <br>Navigation bar<br><br><br><br> is actually adding a piece of code to the footer.inc file. Assuming that all files with the suffix .php3 in your website will appear in the navigation bar, the following is the code saved as include\/navbar.inc: <br><br><?<br><br>\/* Output the navigation bar and link all .php3 files in the site except the current page *\/<br><br># Read directory <br><br>$d = dir(\".\/\");<br><br> echo \"<P ALIGN=\"CENTER\"> | n\";<br><br>while($entry = $d->read())<br><br>{<br><br>\/ \/ Ignore no file condition <br><br>if ( !is_file($entry) )<br><br>continue;<br><br>\/* Separate the file name from the extension. Since . is a special character in regular expressions, it should be introduced *\/<br><br>list($filenm, $fileext) = split(\".\",$entry, 2);<br><br>\/\/ Ignore Non-.php3 files <br><br>if( $fileext != \"php3\" )<br><br>continue;<br><br>\/* Now that we have selected all the .php3 files, let’s search The first line (title) in the file <br><br> is similar to $title=\"something\";<br><br> and separate the above title content as link text *\/<br><br>$linknm = \"\";<br><br>$fp=fopen($entry,\"r\");<br><br>while($buffer=fgets($fp, 4096))<br><br>{<br><br>$buffer = trim($buffer);<br><br>\/\/ We have put the title of each file on the first line of the file for easy search<br><br>\/\/ But when you Changing variable names may cause trouble<br><br>if (ereg(\"title *= *\"\", $buffer))<br><br>{<br><br>\/* We have obtained The title content can be removed based on <br><br>. <br><br> must be processed in PHP code, such as $title = \"blah blah\" *\/<br><br>. eval($buffer);<br><br>\/\/ Then display the link text as title text<br><br>$linknm = $title;<br><br>break;<br><br>}<br><br>}<br><br>fclose($fp);<br><br>if ( $entry == basename($PHP_SELF) )<br><br>echo \"$linknm\";<br><br>else<br><br>echo \"<A HREF=\"$entry\">$linknm<\/A>\";<br><br>echo \" | \";<br><br>} <br><br>$d->close();<br><br>echo \" <\/P>n\";<br><br>?><br><br><br><br>Photo Collection<br><br><br><br>We will refer to HTTP-based authentication, file system functions and file upload functions to maintain the directory where the image files are placed. <br><br>At the same time, we need to create a directory. A page that lists all photos in this directory.<br><br><br><br>File upload<br><br><?<br><br>include(\"include\/common.inc\");<br><br>\/\/ We are here Do another user verification here <br><br>if(!isset($PHP_AUTH_USER)) <br><br>{<br><br>Header(\"WWW-Authenticate: Basic realm=\"$MySiteName\"\") ;<br><br>Header(\"HTTP\/1.0 401 Unauthorized\");<br><br>echo \"Sorry, you are not authorized to upload filesn\";<br><br>exit;<br><br>} <br><br>else <br><br>{<br><br>if ( !($PHP_AUTH_USER==$MyName && $PHP_AUTH_PW==$MyPassword ) )<br><br>{<br><br>\/\/ If it is a wrong username\/password pair, force re-authentication<br><br>Header(\"WWW-Authenticate: Basic realm=\"My Realm\"\");<br><br>Header( \"HTTP\/1.0 401 Unauthorized\");<br><br>echo \"ERROR : $PHP_AUTH_USER\/$PHP_AUTH_PW is invalid.<P>\";<br><br>exit;<br><br>} <br><br>}<br><br>if ( $cancelit ) <br><br>{<br><br>\/\/ When the visitor presses the \"Cancel\" button, it will redirect to the homepage <br><br> header ( \"Location: front_2.php3\" );<br><br>exit;<br><br>}<br><br>function do_upload () {<br><br>global $userfile, $userfile_size, $userfile_name, $userfile_type;<br><br>global $local_file, $error_msg;<br><br>global $HTTP_REFERER;<br><br>if ( $userfile == \"none\" ) {<br><br>$error_msg = \"You did not specify a file for uploading.\";<br><br>return;<br><br>}<br><br>if ( $userfile_size > 2000000 ) <br><br>{<br><br>$error_msg = \"Sorry, your file is too large.\";<br><br>return;<br><br>}<br><br>\/\/ Wherever you have write permission below...<br><br>$upload_dir = \"photos\";<br><br>$local_file = \"$upload_dir\/$userfile_name\";<br><br>if ( file_exists ( $local_file ) ) { <br><br>$error_msg = \"Sorry, a file with that name already exists\";<br><br>return;<br><br>};<br><br>\/\/ You can also use this Check file name\/type pairs to determine what kind of file it is: gif, jpg, mp3...<br><br>rename($userfile, $local_file);<br><br>echo \"The file is uploaded<BR>n \";<br><br>echo \"<A HREF=\"$HTTP_REFERER\">Go Back<\/A><BR>n\";<br><br>}<br><br>$title = \"Upload File\";<br><br>include(\"include\/header.inc\");<br><br>if (empty($userfile) <br> $userfile==\"none\") <br><br>{<br><br>\/\/ Output the following form<br><br>?><br><br><FORM ACTION=\"<? echo \"$PHP_SELF\"; ?>\" ENCTYPE= \"multipart\/form-data\" <br>METHOD=POST><br><br><INPUT TYPE=\"HIDDEN\" NAME=\"MAX_FILE_SIZE\" VALUE=\"2000000\"><br><br><INPUT TYPE =\"FILE\" NAME=\"userfile\" SIZE=\"24\" <br>MAXLENGTH=\"80\"><br><br><BR><BR><br><br><INPUT TYPE=\" SUBMIT\" VALUE=\"Upload File!\" NAME=\"sendit\"><br><br><INPUT TYPE=\"SUBMIT\" VALUE=\"Cancel\" NAME=\"cancelit\"><BR><br><br><\/FORM><br><br><I><FONT SIZE=\"2\">(You may notice a slight delay while <br>we upload your file.)<\/FONT>< ;\/I><br><br><?<br><br>} else {<br><br>if ( $error_msg ) { echo \"<B>$error_msg<\/B><BR> <BR>\"; <br>}<br><br>if ( $sendit ) {<br><br>do_upload ();<br><br>} <br><br>}<br><br>include(\"include\/footer.inc\");<br><br>?><br><br><br><br>Photo Gallery<br><br><br><br><br><br><?<br><br>include(\"include\/common.inc\");<br><br>$title = \"Gallery\";<br><br>include(\"include\/header. inc\");<br><br>?><br><br><P><br><br>Here are some of our family photos. This PHP script can really<br><br>be made better, by splitting into multiple pages. while($entry = $d->read())<br><br>{<br><br>if (is_file(\"photos\/$entry\"))<br><br>echo \"<IMG SRC=\"photos\/$entry\">n\";<br><br>}<br><br>$d->close();<br><br>?><br><br> <?<br><br>include(\"include\/footer.inc\");<br><br>?><br><br><br><br>Also, you can upload the file in the file upload form Add an input element to describe the uploaded file. This element will be stored in the file and then read and displayed by the code in the photo gallery above.<br>\n \n \n\n<\/p>\n<p align=\"left\"><\/p>\n<div style=\"display:none;\">\n<span id=\"url\" itemprop=\"url\">http:\/\/www.bkjia.com\/PHPjc\/314690.html<\/span><span id=\"indexUrl\" itemprop=\"indexUrl\">www.bkjia.com<\/span><span id=\"isOriginal\" itemprop=\"isOriginal\">true<\/span><span id=\"isBasedOnUrl\" itemprop=\"isBasedOnUrl\">http: \/\/www.bkjia.com\/PHPjc\/314690.html<\/span><span id=\"genre\" itemprop=\"genre\">TechArticle<\/span><span id=\"description\" itemprop=\"description\">5. Other miscellaneous items 5.1 Generate images PHP can operate and process images. If you have the GD library installed, you can even generate images using PHP. ? Header(\"Content-type:image\/gif\"); $string=imp...<\/span>\n<\/div>\n<div id="377j5v51b" class=\"art_confoot\"><\/div>"} </script> <meta http-equiv="Cache-Control" content="no-transform" /> <meta http-equiv="Cache-Control" content="no-siteapp" /> <script>var V_PATH="/";window.onerror=function(){ return true; };</script> </head> <body data-commit-time="2023-12-28T14:50:12+08:00" class="editor_body body2_2"> <link rel="stylesheet" type="text/css" href="/static/csshw/stylehw.css"> <header> <div id="377j5v51b" class="head"> <div id="377j5v51b" class="haed_left"> <div id="377j5v51b" class="haed_logo"> <a href="http://www.miracleart.cn/" title="" class="haed_logo_a"> <img src="/static/imghw/logo.png" alt="" class="haed_logoimg"> </a> </div> <div id="377j5v51b" class="head_nav"> <div id="377j5v51b" class="head_navs"> <a href="javascript:;" title="Community" class="head_nava head_nava-template1">Community</a> <div class="377j5v51b" id="dropdown-template1" style="display: none;"> <div id="377j5v51b" class="languagechoose"> <a href="http://www.miracleart.cn/article.html" title="Articles" class="languagechoosea on">Articles</a> <a href="http://www.miracleart.cn/faq/zt" title="Topics" class="languagechoosea">Topics</a> <a href="http://www.miracleart.cn/wenda.html" title="Q&A" class="languagechoosea">Q&A</a> </div> </div> </div> <div id="377j5v51b" class="head_navs"> <a href="javascript:;" title="Learn" class="head_nava head_nava-template1_1">Learn</a> <div class="377j5v51b" id="dropdown-template1_1" style="display: none;"> <div id="377j5v51b" class="languagechoose"> <a href="http://www.miracleart.cn/course.html" title="Course" class="languagechoosea on">Course</a> <a href="http://www.miracleart.cn/dic/" title="Programming Dictionary" class="languagechoosea">Programming Dictionary</a> </div> </div> </div> <div id="377j5v51b" class="head_navs"> <a href="javascript:;" title="Tools Library" class="head_nava head_nava-template1_2">Tools Library</a> <div class="377j5v51b" id="dropdown-template1_2" style="display: none;"> <div id="377j5v51b" class="languagechoose"> <a href="http://www.miracleart.cn/toolset/development-tools" title="Development tools" class="languagechoosea on">Development tools</a> <a href="http://www.miracleart.cn/toolset/website-source-code" title="Website Source Code" class="languagechoosea">Website Source Code</a> <a href="http://www.miracleart.cn/toolset/php-libraries" title="PHP Libraries" class="languagechoosea">PHP Libraries</a> <a href="http://www.miracleart.cn/toolset/js-special-effects" title="JS special effects" class="languagechoosea on">JS special effects</a> <a href="http://www.miracleart.cn/toolset/website-materials" title="Website Materials" class="languagechoosea on">Website Materials</a> <a href="http://www.miracleart.cn/toolset/extension-plug-ins" title="Extension plug-ins" class="languagechoosea on">Extension plug-ins</a> </div> </div> </div> <div id="377j5v51b" class="head_navs"> <a href="http://www.miracleart.cn/ai" title="AI Tools" class="head_nava head_nava-template1_3">AI Tools</a> </div> <div id="377j5v51b" class="head_navs"> <a href="javascript:;" title="Leisure" class="head_nava head_nava-template1_3">Leisure</a> <div class="377j5v51b" id="dropdown-template1_3" style="display: none;"> <div id="377j5v51b" class="languagechoose"> <a href="http://www.miracleart.cn/game" title="Game Download" class="languagechoosea on">Game Download</a> <a href="http://www.miracleart.cn/mobile-game-tutorial/" title="Game Tutorials" class="languagechoosea">Game Tutorials</a> </div> </div> </div> </div> </div> <div id="377j5v51b" class="head_search"> <input id="key_words" onkeydown="if (event.keyCode == 13) searchs('en')" class="search-input" type="text" autocomplete="off" name="keywords" required="required" placeholder="Block,address,transaction,news" value=""> <a href="javascript:;" title="search" onclick="searchs('en')"><img src="/static/imghw/find.png" alt="search"></a> </div> <div id="377j5v51b" class="head_right"> <div id="377j5v51b" class="haed_language"> <a href="javascript:;" class="layui-btn haed_language_btn">English<i class="layui-icon layui-icon-triangle-d"></i></a> <div class="377j5v51b" id="dropdown-template" style="display: none;"> <div id="377j5v51b" class="languagechoose"> <a href="javascript:setlang('zh-cn');" title="簡體中文" class="languagechoosea">簡體中文</a> <a href="javascript:;" title="English" class="languagechoosea">English</a> <a href="javascript:setlang('zh-tw');" title="繁體中文" class="languagechoosea">繁體中文</a> <a href="javascript:setlang('ja');" title="日本語" class="languagechoosea">日本語</a> <a href="javascript:setlang('ko');" title="???" class="languagechoosea">???</a> <a href="javascript:setlang('ms');" title="Melayu" class="languagechoosea">Melayu</a> <a href="javascript:setlang('fr');" title="Fran?ais" class="languagechoosea">Fran?ais</a> <a href="javascript:setlang('de');" title="Deutsch" class="languagechoosea">Deutsch</a> </div> </div> </div> <span id="377j5v51b" class="head_right_line"></span> <div style="display: block;" id="login" class="haed_login "> <a href="javascript:;" title="Login" class="haed_logina ">Login</a> </div> <div style="display: block;" id="reg" class="head_signup login"> <a href="javascript:;" title="singup" class="head_signupa">singup</a> </div> </div> </div> </header> <main> <div id="377j5v51b" class="Article_Details_main"> <div id="377j5v51b" class="Article_Details_main1"> <div id="377j5v51b" class="Article_Details_main1M"> <div id="377j5v51b" class="phpgenera_Details_mainL1"> <a href="http://www.miracleart.cn/" title="Home" class="phpgenera_Details_mainL1a">Home</a> <img src="/static/imghw/top_right.png" alt="" /> <a href="http://www.miracleart.cn/be/" class="phpgenera_Details_mainL1a">Backend Development</a> <img src="/static/imghw/top_right.png" alt="" /> <a href="http://www.miracleart.cn/php-weizijiaocheng.html" class="phpgenera_Details_mainL1a">PHP Tutorial</a> <img src="/static/imghw/top_right.png" alt="" /> <span>5. Other functions of PHP_PHP tutorial</span> </div> <div id="377j5v51b" class="Articlelist_txts"> <div id="377j5v51b" class="Articlelist_txts_info"> <h1 class="Articlelist_txts_title">5. Other functions of PHP_PHP tutorial</h1> <div id="377j5v51b" class="Articlelist_txts_info_head"> <div id="377j5v51b" class="author_info"> <a href="http://www.miracleart.cn/member/887227.html" class="author_avatar"> <img class="lazy" data-src="https://img.php.cn/upload/avatar/000/887/227/63bb7851c9547215.jpg" src="/static/imghw/default1.png" alt="WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB"> </a> <div id="377j5v51b" class="author_detail"> <a href="http://www.miracleart.cn/member/887227.html" class="author_name">WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB</a> </div> </div> </div> <span id="377j5v51b" class="Articlelist_txts_time">Jul 21, 2016 pm 04:08 PM</span> <div id="377j5v51b" class="Articlelist_txts_infos"> <span id="377j5v51b" class="Articlelist_txts_infoss on">php</span> <span id="377j5v51b" class="Articlelist_txts_infoss ">。</span> <span id="377j5v51b" class="Articlelist_txts_infoss ">Function</span> <span id="377j5v51b" class="Articlelist_txts_infoss ">Can</span> <span id="377j5v51b" class="Articlelist_txts_infoss ">image</span> <span id="377j5v51b" class="Articlelist_txts_infoss ">deal with</span> <span id="377j5v51b" class="Articlelist_txts_infoss ">install</span> <span id="377j5v51b" class="Articlelist_txts_infoss ">Library</span> <span id="377j5v51b" class="Articlelist_txts_infoss ">operate</span> <span id="377j5v51b" class="Articlelist_txts_infoss ">generate</span> <span id="377j5v51b" class="Articlelist_txts_infoss ">of</span> </div> </div> </div> <hr /> <div id="377j5v51b" class="article_main php-article"> <div id="377j5v51b" class="article-list-left detail-content-wrap content"> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-5902227090019525" data-ad-slot="3461856641"> </ins> <p> <br> 5. Other miscellaneous items <br><br><br>5.1 Generate images <br><br><br><br>PHP can operate and process images. If you have the GD library installed, you can even generate images using PHP. <br><br><?<br><br>Header("Content-type: image/gif");<br><br>$string=implode($argv," ");<br><br>$im = imagecreatefromgif("images/button1.gif");<br><br>$orange = ImageColorAllocate($im, 220, 210, 60);<br><br>$px = (imagesx($ im)-7.5*strlen($string))/2;<br><br>ImageString($im,3,$px,9,$string,$orange);<br><br>ImageGif($im) ;<br><br>ImageDestroy($im);<br><br>?><br><br> (Translator’s Note: The above code segment lacks comments, please refer to the image processing function section of PHP Manual) <br><br>This code is called in other pages through the following tag <img src="button.php3?text">, and then the above button.php3 code obtains the text value and obtains the image in another Add this value to the file--in the above code, the image file is images/button1.gif--and finally output it to the browser. If you want to use an image button in a form field, but don't want to have to regenerate a new image every time the text on the button changes, you can use this simple method to dynamically generate an image file. <br><br><br><br>5.2 Cookies<br><br><br><br>PHP supports HTTP-based cookies. When needed, you can use cookies just as easily as regular variables. Cookies are pieces of information that the browser saves on the client, so you can know whether anyone on a specific PC has visited your site, the visitor's traces on your site, and so on. A typical example of using cookies is the screening of browser preferences. Cookies are set by the function setcookie(). Like the function header() that outputs HTTP headers, setcookie() must be called before any actual content is output to the browser. The following is a simple example: <br><br><?<br><br>if (empty($VisitedBefore)) <br><br>{<br><br>// If no cookie is set, Assign the current time value to the cookie <br><br>// The last parameter in the function declares the time the cookie is saved <br><br>// In this example it is 1 year <br><br>/ / The time() function returns the time in seconds since January 1, 1970<br><br>SetCookie("VisitedBefore",time(), time()+(60*60*24*365) );<br><br>} <br><br>else <br><br>{<br><br>// Visitors are welcome to come again<br><br>echo "Hello there, welcome back< BR>"; <br><br>// Read the cookie and determine <br><br>if ( (time() - $VisitedBefore) >= "(60*60*24*7)" ) <br><br>echo "Why did you take a week to come back. You should be here more often!? <br>"; <br><br>} <br><br>?><br><br><br><br>5.3 HTTP-based authentication<br><br><br><br>HTTP-based authentication cannot be implemented when PHP is running in CGI mode. We can use the function header() to send an HTTP header to force authentication, and the client browser will pop up a dialog box for entering the username and password. These two variables are stored in $PHP_AUTH_USER and $PHP_AUTH_PW. You can use these two variables to verify legality and allow entry. The following example authenticates a user's login for tnc/nature using a username/password pair: <br><br><?<br><br>if(!isset($PHP_AUTH_USER)) <br><br>{<br><br>Header("WWW-Authenticate: Basic realm="My Realm"");<br><br>Header("HTTP/1.0 401 Unauthorized");<br><br>echo " Text to send if user hits Cancel buttonn";<br><br>exit;<br><br>} <br><br>else <br><br>{<br><br>if ( !($ PHP_AUTH_USER=="tnc" && $PHP_AUTH_PW=="nature") <br>)<br><br>{<br><br>// If it is a wrong username/password pair, force re-authentication<br> <br>Header("WWW-Authenticate: Basic realm="My Realm"");<br><br>Header("HTTP/1.0 401 Unauthorized");<br><br>echo "ERROR : $PHP_AUTH_USER/ $PHP_AUTH_PW is invalid.";<br><br>exit;<br><br>} <br><br>else <br><br>{<br><br>echo "Welcome tnc!";<br><br>}<br><br>?><br><br>In fact, in actual references, it is unlikely to use the obvious user name/password pair in the code snippet above, but instead uses a database or encrypted Password files to access them. <br><br><br><br>5.4 File Upload<br><br><br><br>You can use PHP to implement the file function. Note that the client browser should be Netscape3 or above or IE3 or above.以下就是該功能的簡單演示:<br><br>(?upload.html?):<br><br><HTML><br><br><HEAD><br><br><TITLE>Upload?Your?File






    ENCTYPE="multipart/form-data"?METHOD=POST>


    NAME="MAX_FILE_SIZE"?VALUE="2000000">


    NAME="uploadfile"?SIZE="24"?MAXLENGTH="80">






    NAME="sendit">?


    NAME="cancelit">




    (You?may?notice?a?slight?

    delay?while?we?upload?your?file.)








    下面是處理上傳的文件:

    (?receiver.php3?):


    function?do_upload?()?

    {

    global?$uploadfile,?$uploadfile_size;

    global?$local_file,?$error_msg;

    if?(?$uploadfile?==?"none"?)?

    {

    $error_msg?=?"You?did?not?specify?a?file?for?uploading.";

    return;

    }

    if?(?$uploadfile_size?>?2000000?)?

    {

    $error_msg?=?"Sorry,?your?file?is?too?large.";

    return;

    }

    $the_time?=?time?();

    //?你需要對以下目錄有寫權(quán)限

    $upload_dir?=?"/local/uploads";

    $local_file?=?"$upload_dir/$the_time";

    if?(?file_exists?(?'$local_file'?)?)?

    {

    $seq?=?1;

    while?(?file_exists?(?"$upload_dir/$the_time$seq"?)?)?{?$seq++;?}

    $local_file?=?"$upload_dir/$the_time$seq";

    };

    rename?(?$uploadfile,?$local_file?);

    display_page?();

    }

    function?display_page?()?

    {

    //?這里是你的頁面內(nèi)容

    }





    php3?Receiving?Script






    if?(?$error_msg?)?{?echo?"$error_msg

    ";?
    }

    if?(?$sendit?)?

    {

    do_upload?();

    }?

    elseif?(?$cancelit?)?

    {

    header?(?"Location:?$some_other_script"?);

    exit;

    }?

    else?

    {

    some_other_func?();

    }

    ?>







    5.5?常用函數(shù)



    我們簡單來看看一些常用的函數(shù)。



    Array





    array - generate array

    count - number of array elements

    sort - Array sorting, there are several other sorting functions available

    list - List array elements

    each - Return the next key/value pair

    current - Returns the current array element

    next,prev - Returns the pointers before and after the current array element







    Date and Time



    checkdate - Verify date/time format

    date - Generate date/time format

    time - Current time information

    strftime - Format date/time



    Directory, file system



    chdir - Change directory

    dir - Directory category

    opendir, readdir, closedir - open, read, close the directory

    fopen, fclose - open, close the file

    fgets, fgetss - read the content line by line

    file - Read the entire file into an array variable



    Regular expression



    ereg - Match regular expression

    eregi - Matches regular expressions in case insensitive

    ereg_replace - Matches regular expressions and replaces them

    eregi_replace - Matches regular expressions in case insensitive cases and replaces them

    split - Split the string according to the rules and store it in array form






    String



    AddSlashes - Use a string after adding a slash

    echo - Output one or more strings

    join, implode - Combine array elements into a string

    htmlentities, htmlspecialchars - Convert HTML special characters into HTML tag form

    split - Split the string according to rules and store it in array form

    5.6 Extend our sample homepage



    We will use some of the functions and ideas mentioned above to add more dynamic content to our sample homepage. We can add a navigation bar at the top of each page, and at the same time make the current page automatically not displayed by links; we can also add a user verification form to upload music, images and other files and automatically update the page.
    Navigation bar



    is actually adding a piece of code to the footer.inc file. Assuming that all files with the suffix .php3 in your website will appear in the navigation bar, the following is the code saved as include/navbar.inc:


    /* Output the navigation bar and link all .php3 files in the site except the current page */

    # Read directory

    $d = dir("./");

    echo "

    | n";

    while($entry = $d->read())

    {

    / / Ignore no file condition

    if ( !is_file($entry) )

    continue;

    /* Separate the file name from the extension. Since . is a special character in regular expressions, it should be introduced */

    list($filenm, $fileext) = split(".",$entry, 2);

    // Ignore Non-.php3 files

    if( $fileext != "php3" )

    continue;

    /* Now that we have selected all the .php3 files, let’s search The first line (title) in the file

    is similar to $title="something";

    and separate the above title content as link text */

    $linknm = "";

    $fp=fopen($entry,"r");

    while($buffer=fgets($fp, 4096))

    {

    $buffer = trim($buffer);

    // We have put the title of each file on the first line of the file for easy search

    // But when you Changing variable names may cause trouble

    if (ereg("title *= *"", $buffer))

    {

    /* We have obtained The title content can be removed based on

    .

    must be processed in PHP code, such as $title = "blah blah" */

    . eval($buffer);

    // Then display the link text as title text

    $linknm = $title;

    break;

    }

    }

    fclose($fp);

    if ( $entry == basename($PHP_SELF) )

    echo "$linknm";

    else

    echo "$linknm";

    echo " | ";

    }

    $d->close();

    echo "

    n";

    ?>



    Photo Collection



    We will refer to HTTP-based authentication, file system functions and file upload functions to maintain the directory where the image files are placed.

    At the same time, we need to create a directory. A page that lists all photos in this directory.



    File upload


    include("include/common.inc");

    // We are here Do another user verification here

    if(!isset($PHP_AUTH_USER))

    {

    Header("WWW-Authenticate: Basic realm="$MySiteName"") ;

    Header("HTTP/1.0 401 Unauthorized");

    echo "Sorry, you are not authorized to upload filesn";

    exit;

    }

    else

    {

    if ( !($PHP_AUTH_USER==$MyName && $PHP_AUTH_PW==$MyPassword ) )

    {

    // If it is a wrong username/password pair, force re-authentication

    Header("WWW-Authenticate: Basic realm="My Realm"");

    Header( "HTTP/1.0 401 Unauthorized");

    echo "ERROR : $PHP_AUTH_USER/$PHP_AUTH_PW is invalid.

    ";

    exit;

    }

    }

    if ( $cancelit )

    {

    // When the visitor presses the "Cancel" button, it will redirect to the homepage

    header ( "Location: front_2.php3" );

    exit;

    }

    function do_upload () {

    global $userfile, $userfile_size, $userfile_name, $userfile_type;

    global $local_file, $error_msg;

    global $HTTP_REFERER;

    if ( $userfile == "none" ) {

    $error_msg = "You did not specify a file for uploading.";

    return;

    }

    if ( $userfile_size > 2000000 )

    {

    $error_msg = "Sorry, your file is too large.";

    return;

    }

    // Wherever you have write permission below...

    $upload_dir = "photos";

    $local_file = "$upload_dir/$userfile_name";

    if ( file_exists ( $local_file ) ) {

    $error_msg = "Sorry, a file with that name already exists";

    return;

    };

    // You can also use this Check file name/type pairs to determine what kind of file it is: gif, jpg, mp3...

    rename($userfile, $local_file);

    echo "The file is uploaded
    n ";

    echo "Go Back
    n";

    }

    $title = "Upload File";

    include("include/header.inc");

    if (empty($userfile)
    $userfile=="none")

    {

    // Output the following form

    ?>

    " ENCTYPE= "multipart/form-data"
    METHOD=POST>



    MAXLENGTH="80">












    (You may notice a slight delay while
    we upload your file.)
    < ;/I>


    } else {

    if ( $error_msg ) { echo "$error_msg

    ";
    }

    if ( $sendit ) {

    do_upload ();

    }

    }

    include("include/footer.inc");

    ?>



    Photo Gallery






    include("include/common.inc");

    $title = "Gallery";

    include("include/header. inc");

    ?>



    Here are some of our family photos. This PHP script can really

    be made better, by splitting into multiple pages. while($entry = $d->read())

    {

    if (is_file("photos/$entry"))

    echo "n";

    }

    $d->close();

    ?>


    include("include/footer.inc");

    ?>



    Also, you can upload the file in the file upload form Add an input element to describe the uploaded file. This element will be stored in the file and then read and displayed by the code in the photo gallery above.

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314690.htmlTechArticle5. Other miscellaneous items 5.1 Generate images PHP can operate and process images. If you have the GD library installed, you can even generate images using PHP. ? Header("Content-type:image/gif"); $string=imp...
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Why We Comment: A PHP Guide Why We Comment: A PHP Guide Jul 15, 2025 am 02:48 AM

    PHPhasthreecommentstyles://,#forsingle-lineand/.../formulti-line.Usecommentstoexplainwhycodeexists,notwhatitdoes.MarkTODO/FIXMEitemsanddisablecodetemporarilyduringdebugging.Avoidover-commentingsimplelogic.Writeconcise,grammaticallycorrectcommentsandu

    How to Install PHP on Windows How to Install PHP on Windows Jul 15, 2025 am 02:46 AM

    The key steps to install PHP on Windows include: 1. Download the appropriate PHP version and decompress it. It is recommended to use ThreadSafe version with Apache or NonThreadSafe version with Nginx; 2. Configure the php.ini file and rename php.ini-development or php.ini-production to php.ini; 3. Add the PHP path to the system environment variable Path for command line use; 4. Test whether PHP is installed successfully, execute php-v through the command line and run the built-in server to test the parsing capabilities; 5. If you use Apache, you need to configure P in httpd.conf

    PHP Syntax: The Basics PHP Syntax: The Basics Jul 15, 2025 am 02:46 AM

    The basic syntax of PHP includes four key points: 1. The PHP tag must be ended, and the use of complete tags is recommended; 2. Echo and print are commonly used for output content, among which echo supports multiple parameters and is more efficient; 3. The annotation methods include //, # and //, to improve code readability; 4. Each statement must end with a semicolon, and spaces and line breaks do not affect execution but affect readability. Mastering these basic rules can help write clear and stable PHP code.

    Your First PHP Script: A Practical Introduction Your First PHP Script: A Practical Introduction Jul 16, 2025 am 03:42 AM

    How to start writing your first PHP script? First, set up the local development environment, install XAMPP/MAMP/LAMP, and use a text editor to understand the server's running principle. Secondly, create a file called hello.php, enter the basic code and run the test. Third, learn to use PHP and HTML to achieve dynamic content output. Finally, pay attention to common errors such as missing semicolons, citation issues, and file extension errors, and enable error reports for debugging.

    What is PHP and What is it Used For? What is PHP and What is it Used For? Jul 16, 2025 am 03:45 AM

    PHPisaserver-sidescriptinglanguageusedforwebdevelopment,especiallyfordynamicwebsitesandCMSplatformslikeWordPress.Itrunsontheserver,processesdata,interactswithdatabases,andsendsHTMLtobrowsers.Commonusesincludeuserauthentication,e-commerceplatforms,for

    PHP 8 Installation Guide PHP 8 Installation Guide Jul 16, 2025 am 03:41 AM

    The steps to install PHP8 on Ubuntu are: 1. Update the software package list; 2. Install PHP8 and basic components; 3. Check the version to confirm that the installation is successful; 4. Install additional modules as needed. Windows users can download and decompress the ZIP package, then modify the configuration file, enable extensions, and add the path to environment variables. macOS users recommend using Homebrew to install, and perform steps such as adding tap, installing PHP8, setting the default version and verifying the version. Although the installation methods are different under different systems, the process is clear, so you can choose the right method according to the purpose.

    How Do You Handle File Operations (Reading/Writing) in PHP? How Do You Handle File Operations (Reading/Writing) in PHP? Jul 16, 2025 am 03:48 AM

    TohandlefileoperationsinPHP,useappropriatefunctionsandmodes.1.Toreadafile,usefile_get_contents()forsmallfilesorfgets()inaloopforline-by-lineprocessing.2.Towritetoafile,usefile_put_contents()forsimplewritesorappendingwiththeFILE_APPENDflag,orfwrite()w

    python if else example python if else example Jul 15, 2025 am 02:55 AM

    The key to writing Python's ifelse statements is to understand the logical structure and details. 1. The infrastructure is to execute a piece of code if conditions are established, otherwise the else part is executed, else is optional; 2. Multi-condition judgment is implemented with elif, and it is executed sequentially and stopped once it is met; 3. Nested if is used for further subdivision judgment, it is recommended not to exceed two layers; 4. A ternary expression can be used to replace simple ifelse in a simple scenario. Only by paying attention to indentation, conditional order and logical integrity can we write clear and stable judgment codes.

    See all articles