首頁 >後端開發 >php教程 >php上傳檔案程式碼 php檔案上傳程式碼 php curl 上傳檔案 php 多檔案上

php上傳檔案程式碼 php檔案上傳程式碼 php curl 上傳檔案 php 多檔案上

WBOY
WBOY原創
2016-07-29 08:54:061033瀏覽

<code><span><!DOCTYPE hmtl></span><span><<span>html</span>></span><span><<span>head</span>></span><span><<span>meta</span><span>charset</span>=<span>"utf8"</span>></span><span><<span>title</span>></span>upload<span></<span>title</span>></span><span></<span>head</span>></span><span><<span>body</span>></span><span><<span>form</span><span>action</span>=<span>"upload_file.php"</span><span>method</span>=<span>"post"</span><span>enctype</span>=<span>"multipart/form-data"</span>></span><span><<span>label</span><span>for</span>=<span>"file"</span>></span>Filename:<span></<span>label</span>></span><span><<span>input</span><span>type</span>=<span>"file"</span><span>name</span>=<span>"file"</span><span>id</span>=<span>"file"</span> /></span><span><<span>br</span> /></span><span><<span>input</span><span>type</span>=<span>"submit"</span><span>name</span>=<span>"submit"</span><span>value</span>=<span>"submit"</span> /></span><span><<span>br</span> /></span><span></<span>form</span>></span><span></<span>body</span>></span><span></<span>html</span>></span></code>
<code><span><span><?php</span><span>if</span>((<span>$_FILES</span>[<span>'file'</span>][<span>'type'</span>] == <span>"image/gif"</span>)||
  (<span>$_FILES</span>[<span>'file'</span>][<span>'type'</span>] == <span>"image/jpeg"</span>)||
  (<span>$_FILES</span>[<span>'file'</span>][<span>'type'</span>] == <span>"image/pjpeg"</span>)&&
  (<span>$_FILES</span>[<span>'file'</span>][<span>'size'</span>] < <span>20000</span>))
  {
     <span>if</span> (<span>$_FILES</span>[<span>"file"</span>][<span>"error"</span>] > <span>0</span>)
     {
        <span>echo</span><span>"Error: "</span> . <span>$_FILES</span>[<span>"file"</span>][<span>"error"</span>] . <span>"<br />"</span>;
     }
     <span>else</span>
     {
        <span>echo</span><span>"<html>"</span>;
        <span>echo</span><span>"<body>"</span>;
        <span>echo</span><span>"<meta charset='utf8'>"</span>;
        <span>echo</span><span>"Upload: "</span> . <span>$_FILES</span>[<span>"file"</span>][<span>"name"</span>] . <span>"<br />"</span>;
        <span>echo</span><span>"Type: "</span> . <span>$_FILES</span>[<span>"file"</span>][<span>"type"</span>] . <span>"<br />"</span>;
        <span>echo</span><span>"Size: "</span> . (<span>$_FILES</span>[<span>"file"</span>][<span>"size"</span>] / <span>1024</span>) . <span>" Kb<br />"</span>;
        <span>echo</span><span>"Stored in: "</span> . <span>$_FILES</span>[<span>"file"</span>][<span>"tmp_name"</span>];
        <span>echo</span><span>"</body>"</span>;
        <span>echo</span><span>"</html>"</span>;
        <span>if</span>(file_exists(<span>"upload/"</span> . <span>$_FILES</span>[<span>'file'</span>][<span>'name'</span>]))
        {
            <span>echo</span><span>$_FILES</span>[<span>'file'</span>][<span>'name'</span>].<span>"already exists. "</span>;
        }
        <span>else</span>
        {
             move_uploaded_file(<span>$_FILES</span>[<span>"file"</span>][<span>"tmp_name"</span>],
             <span>"/usr/local/nginx/html/upload/"</span> . <span>$_FILES</span>[<span>"file"</span>][<span>"name"</span>]);
             <span>echo</span><span>"Stored in: "</span> . <span>"/usr/local/nginx/html/upload/"</span> . <span>$_FILES</span>[<span>"file"</span>][<span>"name"</span>];
        }
     }
  }
  <span>else</span>
  {
     <span>echo</span><span>"Invaild file"</span>;
  }
<span>?></span></span></span></code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介紹了php上傳檔案程式碼,包含了上傳檔案,php方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn