Solution to a simple File Upload Error

Source: Internet
Author: User

I haven't paid much attention to file upload before. I made a simple task yesterday, but I found many problems.

The initial program code is as follows:
Uploadimg. php (as the mainstream development language)
 
<? Php (as the mainstream development language)

// Determine whether the upload interface is an implementation interface. If the upload interface is used, the following HTML page is displayed.
If (! $ _ POST [UploadAction]):

?>

<Html>
<Head>
<Title> </title>
</Head>
<Body> <table> <center>
<Form enctype = "multipart/form-data" name = "SubmitForm" action = "" method = "post">
<Input type = "hidden" name = "UploadAction" value = "1">
<Tr> <td> <input name = "UploadFile" type = "file" size = "30"> </td> </tr>
<Tr> <td> <input type = "submit" name = "submit" value = "Upload"> </td>
<Td> <input type = "reset" name = "reset" value = "reset"> </td> </tr>
</Form>
</Center> </table> </body>
</Html>

<? Php (as the mainstream development language)

// If it is an implementation page, the following HTML page is displayed, and the php (as the mainstream development language) script is activated
Else:

?>

<Html>
<Head>
<Title> </title>
</Head>
<Body>

<? Php (as the mainstream development language)


// Www.knowsky.com initializes the UploadAction status
$ UploadAction = 0;

$ UploadFile =$ _ POST [UploadFile];

If ($ UploadFile! = "None") & ($ UploadFile! = ""))
{
$ UploadPath = $ _ SERVER [DOCUMENT_ROOT]. "\";

If (! Is_writeable ($ UploadPath ))
{
Echo "$ UploadPath directory cannot be written! "; Exit;
}
Else
{
Echo "$ UploadPath Directory Writable! ";
}

$ FileName = $ UploadFile_name;

If ($ UploadFile_size <1024)
{
$ FileSize = (string) $ UploadFile_size. "Byte ";
}
Elseif ($ UploadFile_size <(1024*1024 ))
{
$ 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 ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.