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.
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:
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/";
Question 2
Find the save method in the ThinkPHP\Library\Think\Upload\Driver\Local.class.php file:
Change
if (!move_uploaded_file($file['tmp_name'], $filename))
to
if (!move_uploaded_file($file['tmp_name'], iconv('utf-8','gb2312',$filename)))
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;
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!