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 ))