China Letter MySQL Database repair tool

Source: Internet
Author: User

Well, I admit I'm a wuss.

Today in the Laravel framework to write a file upload part. The discovery path always does not match. But eventually it was settled.

Let me share my learning experience below.

Client

<form method= "POST" action= "enctype=" Muitipart/form-data ">

<input type= "File" name= "MyFile"/>

<input type= "Submit" name= "submit" value= "Submit"/>

</form>

Submit to the server side.

$file = Input::file (' myfile ');

if ($file, IsValid ()) {

Verify that the uploaded file is valid.

$clientName = $file-Getclientoriginalname (); //Client file name:

$tmpName = $file->getfilename (); // cache filenames in the TMP folder such as php8933.tmp of this type.

$realPath = $file-Getrealpath (); This represents the absolute path of the file that is cached in the TMP folder

For example mine is:G:\xampp\tmp\php5A69.tmp

Note here that if I use the next Move method, Getrealpath () will not find the path to the file. Because the file has been moved.

So here's how the file is uploaded, a temporary directory where the file is uploaded, and then the PHP function is used to move the file to the specified folder.

$entension = $file-Getclientoriginalextension (); The suffix of the upload file.

$mimeTye = file-GetMimeType ();//mimetype should not be unfamiliar to everyone. The result I got was image/jpeg.

One thing to note here is that before we used Mime_content_type (), after php5.3, we started using FileInfo to get the MIME type of the file. So join the PHP_ FileInfo PHP extension. Under Windows is Php_fileinfo.dll, remove the semicolon from the front extension=php_fileinfo.dll in the php.ini file. Of course, restart the server.

Finally we use

$path = Move (' storage/uploads '), $file

If you write like this, the default will be placed in our public/storage/uploads/php79db.tmp

It looks like it's not what we want, if we want to place it in the uploads directory in the app's storage directory, and we need to rename it.

$path = Move (App_path () $file. /storage/uploads ', $newName);

here App_path () is the path where the app folder is located. $newName can be the name of a file that you get through an algorithm. It is not possible to repeat the conflict. for example $newName = MD5 (date (' Ymdhis '). $clientName). ".". $extension;

Use the date and client file names in conjunction with the MD5 algorithm to encrypt the results. Don't forget to add the original extension name to the file later.

Well, I started to write a program, and now it's a virtue.

Best Wishes.

}



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.