Php File Upload Program (two simple File Upload programs)/* these two File Upload programs are very simple and suitable for beginners to learn php File Upload instance tutorials.
Php tutorial File Upload Program (two simple File Upload programs)
/*
These two File Upload programs are very simple and suitable for beginners to learn php File Upload instance tutorials.
*/
If (! $ Uploadaction ):
?>
<Html>
<Head>
<Title> file upload interface </title>
</Head>
<Body>
<Table>
<Tr align = "center">
<Td> <form enctype = "multipart/form-data" name = "submitform" action = "upload. php" method = "post">
<Input type = "hidden" name = "max_file_size" value = "1000000"> <input type = "hidden" name = "uploadaction" value = "1">
</Td> </tr>
<Tr align = "center">
<Td> <input name = "uploadfile" type = "file" size = "30"> </td>
</Tr>
<Tr align = "center">
<Td> <input name = "submit" value = "submit" type = "submit"> </td>
<Td> <input name = "reset" value = "reset" type = "reset"> </td>
</Tr>
</Form>
</Table>
</Center>
</Body>
</Html>
<?
Else:
?>
<Html>
<Head>
<Title> file upload code </title>
</Head>
<Body>
<?
$ Uploadaction = 0;
Echo "good! ";
$ Timelimit = 60;/* set the time-out period. The default time is 30 seconds. If the value is 0, the time-out period is not limited */
Set_time_limit ($ timelimit );
If ($ uploadfile! = "None "))
{
$ Uploadpath = addslashes (dirname ($ path_translated). "upload"; // upload File Storage path
$ Filename = $ uploadpath. $ uploadfile_name; // Upload File Name
If ($ uploadfile_size <1024) // upload the file size
{
$ 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). "mb ";
}
If (! File_exists ($ filename ))
{
If (copy ($ uploadfile, $ filename ))
{Echo "File $ uploadfile_name ($ filesize) uploaded successfully! ";}
Else
{Echo "File $ uploadfile_name Upload Failed! ";}
Unlink ($ uploadfile );
}
Else
{Echo "File $ uploadfile_name already exists! ";}
}
Else
{Echo "You have not selected any file upload! ";}
Set_time_limit (30); // restores the default timeout value.
?>
<Br> <a href = "upload. php"> return </a>
</Body>
</Html>
<?
Endif;
?>
Method 2
<Html>
<Head>
<Title> File Upload </title>
</Head>
<Body>
<Table>
<Form enctype = "multipart/form-data" name = myform method = "post">
<Tr> <td> file Upload </td> <input name = "myfile" type = "file"> </td> </tr>
<Tr> <td colspan = "2"> <input name = "submit" value = "Upload" type = "submit">
</Form>
<? Php
If (isset ($ submit )){
If ($ myfile! = "None "){
$ Upload_dir = "c: winnttemp ";
$ Up = copy ($ myfile, $ upload_dir );
If ($ up = 1 ){
Print ("File Uploaded successfully! ");
}
Else {
Print ("File Upload Failed .");
}
Unlink ($ myfile );
}
Else {
Print ("You have not uploaded any files ");
}
}
?>
</Td> </tr>
</Table>
</Body>
</Html>