为什么php并不总是上传文件

问题描述 投票:0回答:2

在PHP页面上,我调用包含标准PHP上传过程的上载函数。调用函数后,我进行重定向(尝试使用窗口。位置或标头())。

奇怪的是,一切正常好几次,那么它将不再上传了(

uploadOK

也不是0)。它只是不会将文件移至服务器上。
,然后我将重定向,上传将重新开始工作。我将重定向放回原处,上传仍然可以工作几次,然后再次停止...您是否知道为什么?

另一个奇怪的是,即使它不起作用,上传功能仍然返回正确的路径+文件名,但它不会回荡“文件...已上传”。

我怀疑问题可能在move_uploaded_file()函数中...但是它不会返回0,因为“错误...”不会回荡。

无需在上传之后调用重定向,每次上传均处于上传。

PHP页面:

$_SESSION["temp_file_name"]="../".UploadFisier($_FILES["fileToUpload"], $_SESSION["ID_CLASA"]."_".$id_item."_temp_".UserIdLogat($dbocr)."_", "../teme/", ""); header("Location: trimite_tema_script.php");

上传函数:

function UploadFisier($file, $suffix, $target_dir, $maxsize) { if ($maxsize=="") { $maxsize=3000000; } if ($target_dir=="") { $target_dir="../upload/"; } $target_empty_file=$target_dir.$suffix; $target_file = $target_empty_file.basename($file["name"]); $uploadOk = 1; if ($target_file != $target_empty_file) { if ($file["size"] > $maxsize) { echo "file too large"; $uploadOk = 0; } } else { echo "no file selected."; $uploadOk = 0; } if ($uploadOk == 1) { //we overwrite if (file_exists($target_file)) { unlink($target_file); } if (move_uploaded_file($file["tmp_name"], $target_file)) { echo "File ". basename( $file["name"]). " was uploaded."; //we output the path and filename without the "../" at the beginning $linksave=substr($target_file, 3); } else { echo "Error...."; } } echo "uploadOk ".$uploadOk; return $linksave; }
    

检查php.ini中的file_uploads值
file_uploads = On
php http-redirect upload
2个回答
0
投票

将试用/捕捉到您的代码中。也许您会发现有关错误的更多信息。

function UploadFisier($file, $suffix, $target_dir, $maxsize) { try { // your code } catch (\Exception $e) { echo $e->getMessage(); die(); } }
    

0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.