How can I use php to upload a fixed simple file?

Source: Internet
Author: User
How can I use php to upload a fixed simple file? 1. fixed a file to be uploaded to the server. the file name is fixed and does not need to be specified.
2. Upload and save the file in a specified folder. if there is a file with the same name, delete the original one.

How is the above functions the simplest?


Reply to discussion (solution)

/* Upload error
0 uploaded successfully
1. the file size exceeds the server space.
2. the size of the file to be uploaded exceeds the browser limit.
3. only part of the file is uploaded.
4. the file to be uploaded is not found.
5. the temporary folder on the server is lost.
6. An error occurred while writing the file to the temporary folder.
*/
$ File_type = array ('jpg ', 'PNG', 'GIF', 'Doc', 'txt '); // sets the upload category
$ File_name = 'myfile _ name'; // sets the file name after Upload.
$ File_dir = 'upimg '; // sets the upload directory.
If ($ _ POST ['submitpic ']) {
$ Files = $ _ FILES ['mypic '];
// Determine the error level
If ($ files ['erorr']! = 0 ){
Exit ('Upload error ');
}
// Determine whether the upload type meets the conditions
$ UpName = $ files ['name']; // Get the name of the uploaded file
$ Uptype = explode ('.', $ upName); // Convert it to an array
$ Uptype = end ($ uptype); // Obtain the file type
If (! In_array ($ uptype, $ file_type )){
Exit ('Type invalid ');
}
// Move the file to the specified folder
If (move_uploaded_file ($ files ['tmp _ name'], $ file_dir. '/'. $ file_name. '.'. $ uptype )){
Echo "Upload successful! ";
}
}
?>

The answer is No.
If the uploaded file is a linux password or Windows registry file, would you like it?

Move_uploaded_file

There is no problem with uploading. now, how does one omit the process of selecting files and submitting them.

Check the php file upload. there is no need to consider so many things.

The success rate of FTP uploading is not guaranteed.


The problem is really amazing!

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.