当我按以下顺序使用函数时,我正在警告停止使用PHP中的脚本:
move_uploaded_file() 首先使用
并在此之后包括下一个功能:
file_get_contents() 二手
我收到警告,并显示以下消息:
file_get_contents(D:\ Programs \ WAMP \ WAMP_Server \ tmp \ phpD8E2.tmp):无法打开流:无此文件或目录
但是,如果我反转这些功能:file_get_contents() first然后使用move_uploaded_file()-一切正确,没有错误,并且可以正常工作。哪里有问题?我的代码有以下错误:
/* File management variables */
$filename = $_FILES["uploadFile"]["name"];
$uploadedFile = $_FILES['uploadFile']['tmp_name'];
$uploadedFileType = $_FILES['uploadFile']['type'];
$target_dir = '../uploads/';
$target_dir_file = $target_dir . basename($filename);
$textFileType = strtolower(pathinfo($target_dir_file,PATHINFO_EXTENSION));
/* First: used move_uploaded_file() func */
move_uploaded_file($uploadedFile, $target_dir_file);
/* Second: used file_get_contents() func */
$dbPath = fopen('../database/database.txt', 'a');
$uploadedFile = file_get_contents($uploadedFile);
fwrite($dbPath, $uploadedFile);
fclose($dbPath);
如果颠倒了这两个功能
/* First: used file_get_contents() func */
$dbPath = fopen('../database/database.txt', 'a');
$uploadedFile = file_get_contents($uploadedFile);
fwrite($dbPath, $uploadedFile);
fclose($dbPath);
/* Second: used move_uploaded_file() func */
move_uploaded_file($uploadedFile, $target_dir_file);
没事,脚本可以正常运行。
为什么在使用第一个move_uploaded_file()函数之后和file_get_contents()函数之后使用错误,但是反向后它可以正常工作吗?如何解决却不撤消?
这是因为move_uploaded_file ( string $filename , string $destination )
很好...将$filename
移到了新的$destination
。因此,它在原始路径下不再可用。
鉴于您的第一个示例,您应该这样做:
$uploadedFile = file_get_contents($target_dir_file);