Home > php教程 > php手册 > body text

一个简单上传文件出错的解决

WBOY
Release: 2016-06-13 10:31:31
Original
983 people have browsed it

以前没怎么注意搞过文件上传,昨天搞了一个简单的却发现问题还挺多。

刚开始的程序代码如下:
uploadimg.php(做为现在的主流开发语言)
 
(做为现在的主流开发语言)

//判断是上载界面还是实现界面,如果是上载界面,显示下面的HTML页面
if(!$_POST[UploadAction]):

?>










       


(做为现在的主流开发语言)

//如果是实现页面,显示下面的HTML页面,并激活php(做为现在的主流开发语言)脚本
else:

?>





(做为现在的主流开发语言)


//www.knowsky.com初始化UploadAction的状态
$UploadAction=0;

$UploadFile=$_POST[UploadFile];

if(($UploadFile!="none") && ($UploadFile!=""))
{
        $UploadPath=$_SERVER[DOCUMENT_ROOT]."\";

        if (!is_writeable($UploadPath))
        {
                echo "$UploadPath目录不可写!"; exit;
        }
        else
        {
                echo " $UploadPath 目录可写!";
        }

        $FileName=$UploadFile_name;

        if($UploadFile_size        {
                $FileSize=(string)$UploadFile_size."字节";
        }
        elseif($UploadFile_size        {
                $FileSize=number_format((double)($UploadFile_size/1024),1)."KB";
        }
        else
        {
                $FileSize=number_format((double)($UploadFile_size/(1024*1024)),1)."KB";
        }
        if(!file_exists($UploadPath.$FileName))
        {
                if(move_uploaded_file($UploadFile,$UploadPath.$FileName))

source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template