Maison  >  Article  >  développement back-end  >  Comment dépanner la fonction Move_uploaded_file() ?

Comment dépanner la fonction Move_uploaded_file() ?

Susan Sarandon
Susan Sarandonoriginal
2024-10-18 14:15:03422parcourir

How to Troubleshoot the Move_uploaded_file() Function?

Troubleshooting the Move_uploaded_file() Function

The move_uploaded_file() function plays a crucial role in file uploading mechanisms. However, when encountered with non-functional issues, meticulous troubleshooting is essential.

To address the question, the initial step is to activate PHP error reporting. This will display detailed error messages from the move_uploaded_file() function, providing valuable insights into the problem.

Furthermore, examining the $_FILES'image' variable is pivotal. This variable will indicate any errors encountered during file uploading. In the specific case outlined, an incorrect filename was provided.

To resolve the issue, it is recommended to utilize the 'tmp_name' key of the $_FILES['image'] array instead of 'name'. This is because the uploaded file is initially stored in a temporary location. By utilizing the following code, the file will be moved to the desired directory:

move_uploaded_file($_FILES['image']['tmp_name'], __DIR__.'/../../uploads/'. $_FILES["image"]['name']);
// echo "Uploaded";

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn