I have almost learned the basic syntax of PHP, now I am starting to learn how to implement the file upload function of PHP. The move_uploaded_file method is used in the function, and an error is reported when running: failed to open stream.
After checking the information, I summarized several possible reasons and solutions for this error.
Reason 1: The writing of the directory to be moved is incorrect
My directory is as follows:
This is an example from the fourth edition of "PHP and MySQL Web Development". My PHP version is 7.0.2, and a failed to open stream error occurred when executing it. There are two solutions to this error: first, write an absolute path, such as "D:/uploads/"; second: when using a relative path, use "./uploads/" to move the file to the uploads directory under the current default directory. or use "../uploads/" to move the file to the uploads directory under the parent directory of the current directory.
Cause 2: The directory you moved to does not exist
If the directory you moved to does not exist, a failed to open stream error will also be reported. Creating the corresponding directory can solve the problem.
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });The above introduces the failed to open stream error handling of move_uploaded_file, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.