How to upload files in PHP _ PHP Tutorial

Source: Internet
Author: User
Upload files in PHP. Php (as the mainstream development language) also supports file upload, but not all websites that support php (as the mainstream development language) support this function, in particular, php-free (as the mainstream development language) supports file upload, but not all websites that support php (as the mainstream development language) support this function, especially for free websites.
  
To implement the upload, you must first add the"   
           
When uploading using php (as the mainstream development language), you need to perform a detailed check on the content, such as whether to allow reading and writing files, file format, whether the file size is within your specified size, and so on.
  
   $ File_size_max = 1000000;
// Limit the maximum file upload capacity (bytes)
$ Store_dir = "/public/www/upload /";
// Storage location of uploaded files
$ Accept_overwrite = true;
// Allow reading and writing files
// Check the file size
If ($ upload_file_size> $ file_size_max ){
Echo "Sorry, your file capacity exceeds the limit ";
Exit;
}
// Check the read/write file
If (file_exists ($ store_dir. $ upload_file_name )&&&&! $ Accept_overwrite ){
Echo "the file already exists and cannot be copied ";
Exit;
}
// Copy the file to the specified directory
If (! @ Copy ($ upload_file, $ store_dir. $ upload_file_name )){
Echo "failed to copy the file ";
Exit;
}
Echo "file uploaded ";
?>
  
Note that when uploading files, php (as the mainstream development language) copies the files to the temporary directory (temp) on the server ), then, use the "copy ()" function of php (as the current mainstream development language) to copy files from the temporary directory to the storage directory you specified. Because the program uses a temporary directory for work, if the server blocks the above functions due to security concerns, you cannot use the php (as the mainstream development language) upload function.
  
In addition, you also need to set the file mode to 777 (CHMOD 777) for the uploaded file directory. otherwise, php (as the mainstream development language) will not have the permission to read and write files.

Http://www.bkjia.com/PHPjc/509087.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/509087.htmlTechArticlephp (as the mainstream development language) also supports the ability to upload files, but not all websites that support php (as the mainstream development language) support this function, especially free...

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.