Which of the following experts can help modify the name of the uploaded PHP file?

Source: Internet
Author: User
PHP uploads a file and changes its name. who will help to modify the code under "accept Upload"? who will add the code for modifying the source file name at the time? thank you. If & nbsp; ($ _ SERVER ['request _ method'] & nbsp ;=& nbsp; 'post' & nbsp; & amp; & nbsp; isset ($ _ POST [the name of the PHP file to be uploaded. who can modify it?
The following code only accepts the upload. who will add a code that modifies the source file name at a time? thank you.


If ($ _ SERVER ['request _ method'] = 'post' & isset ($ _ POST ['sub '])
{

$ Myfile = $ _ FILES ["myfile"];

$ MyfileType = substr ($ myfile ['name'], strrpos ($ myfile ['name'], ".") + 1 );

If ($ myfile ['size']> $ maxSize)
{
$ Result = 1;
}
Else if (! In_array ($ myfileType, $ fileTypes ))
{
$ Result = 2;
}
Elseif (is_uploaded_file ($ myfile ['tmp _ name'])
{
$ ToFile = $ uploadDir. '/'. $ myfile ['name'];

If (@ move_uploaded_file ($ myfile ['tmp _ name'], $ toFile )){
{
$ Result = 0;
}
Else
{
$ Result =-1;
}
}
Else
{
$ Result = 1;
}
}

?>

------ Solution --------------------
$ ToFile = $ uploadDir. '/'. $ myfile ['name'];
This is the target file name
Just change it.
------ Solution --------------------
Reference:
$ ToFile = $ uploadDir. '/'. $ myfile ['name'];
This is the target file name
Just change it.


$ Date = date ('ymdhis ', time ());
$ ToFile = $ uploadDir. '/'. $ date. $ myfile ['name'];

Good guys do it to the end

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.