php file upload process (two simple file upload program)

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags beginners echo example file file upload filesize html it is

php tutorial file upload program (two simple file upload program)
/ *
These two file upload program is very simple, it is suitable for beginners to learn php file upload examples tutorial Oh.
* /

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 timeout limit The default time is 30 seconds Unlimited when set to 0 * /
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 file size
{
$ filesize = (string) $ uploadfile_size. "Bytes";
}
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) upload success!";}
else
{echo "file $ uploadfile_name upload failed!";}

unlink ($ uploadfile);
}
else
{echo "file $ uploadfile_name already exists!";}
}
else
{echo "You did not choose any file upload!";}

set_time_limit (30); // Restore the default timeout setting

?>

<br> <a href= "upload.php"> Back </a>

</ body>
</ html>

<?
endif;
?>

Method Two

<html>
<head>
<title> File Upload </ title>
</ head>
<body>
<table>
<form enctype = "multipart / form-data" name = myform method = "post">
<tr> <td> File Upload </ td> <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 upload success!");
}
else {
print ("file upload failed.");
}
unlink ($ myfile);
}
else {
print ("You did not upload any files");
}
}
?>
</ td> </ tr>
</ table>
</ body>
</ html>

Related Article

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.