Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to copy Files with php

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Php how to achieve file replication, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Php to achieve file replication methods: 1, to create a PHP example file; 2, through the "protected function fileCopy (string $file, string $path) {.}" method to achieve file replication.

This article operating environment: Windows7 system, PHP7.1, Dell G3 computer.

How does php copy files?

Php file processing: file copy

The code is as follows:

/ * * @ description: file copy * @ param string $file file * @ param string $path file path * @ return: * / protected function fileCopy (string $file, string $path) {$dir=dirname ($file); $fileName= str_replace ($dir. '/','', $file); / / get the file name if (! is_dir ($path)) {/ / determine whether the directory exists / / create a mkdir (iconv ("UTF-8", "GBK", $path), 0777) / / the iconv method is to prevent Chinese garbled, and to ensure that you can create a recognized Chinese directory. If you do not use the iconv method format, you will not be able to create a Chinese directory. The recursive mode of the third parameter is turned on. The default is off} copy (public_path ($file), $path.$fileName); / / public_path () is the absolute path of the public directory generated by laravel's native method}

The iconv method is to prevent Chinese garbled code and to ensure that you can create a recognized Chinese directory. If you do not use the iconv method format, you will not be able to create a Chinese directory.

The second parameter is permission. The default is 0777, that is, there is no write permission to click and view after the highest permission is created.

The recursive mode of the third parameter is enabled by default. If it is enabled, it will be detected according to your incoming directory. A parent directory will be created based on your incoming path, and then a subdirectory will be created recursively until the directory is complete. If it is not enabled, only a first-level directory will be created.

After reading the above, have you mastered how php can copy files? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report