What should I do if PHP prompts that the upload root directory does not exist?

王林
Release: 2023-03-12 16:04:02
Original
2910 people have browsed it

Solution to the problem when PHP prompts that the upload root directory does not exist: first grant permissions to the root directory and check whether the problem is solved; if the problem is not solved, use the mkdir command to create a new folder; finally, give the newly created folder the highest permissions.

What should I do if PHP prompts that the upload root directory does not exist?

The operating environment of this article: windows10 system, php 7, thinkpad t480 computer.

Problem restoration:

After trying to upload a picture, I got a prompt: "The upload root directory does not exist! Please try to create it manually."

Solution:

Try to give permission first, and if the problem still cannot be solved, delete the folder. Then use the mkdir command to create a new folder and give it 777 permissions.

Question 2:

I encountered the following problems during the development process of using ThinkPHP3 to upload images:

The upload root directory does not exist! Please try to create manually: ./Uploads/; the uploaded pictures have garbled Chinese names; when uploading files, a folder named after the current date will be automatically generated and the files will be saved in it.

Note: The development environment is Xampp under Windows

Attached is the code before the problem is solved:

What should I do if PHP prompts that the upload root directory does not exist?

The following are three questions Solution:

Problem 1

When checking information, some netizens said that this is a folder permission problem. It can be solved as follows:
For example, if you want to save the uploaded pictures to ./ In the Uploads directory, set rootPath to './' and savePath to the path to be saved. Be careful not to put "./" in front. The final saving directory path is ./Uploads/1/.

$upload->rootPath = "./"; $upload->savePath = "Uploads/$uid/";
Copy after login

Question 2

Find the save method in the ThinkPHP\Library\Think\Upload\Driver\Local.class.php file:

What should I do if PHP prompts that the upload root directory does not exist?

Change

if (!move_uploaded_file($file['tmp_name'], $filename))
Copy after login

to

if (!move_uploaded_file($file['tmp_name'], iconv('utf-8','gb2312',$filename)))
Copy after login

Question 3

When uploading, the subdirectory is automatically used to save the uploaded file by default, that is, $upload->autoSub = true; Just set it to false.
Add the following code to the upload parameters in the code:

$upload->autoSub = false;
Copy after login

Recommended learning:php training

The above is the detailed content of What should I do if PHP prompts that the upload root directory does not exist?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!