问题描述
这是两个错误
警告:move_uploaded_file():无法在第28行的C:\ xampp \ htdocs \ file_upload \ upload.php中将'C:\ xampp \ tmp \ php7D69.tmp'移动到'/uploads53e866b24977d1.48375376.pdf' /p>
Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\php7D69.tmp' to '/uploads53e866b24977d1.48375376.pdf' in C:\xampp\htdocs\file_upload\upload.php on line 28
这是我的HTML
<form method="POST" action="upload.php" enctype="multipart/form-data">
<label for="">Upload Your Cv</label><input type="file" name="file">
<input type="submit" value="upload">
</form>
这是我的PHP
if (isset($_FILES['file'])) {
$file = $_FILES['file'];
// print_r($file); just checking File properties
// File Properties
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$fiel_size = $file['size'];
$file_error = $file['error'];
// Working With File Extension
$file_ext = explode('.', $file_name);
$file_fname = explode('.', $file_name);
$file_fname = strtolower(current($file_fname));
$file_ext = strtolower(end($file_ext));
$allowed = array('txt','pdf','doc');
if (in_array($file_ext,$allowed)) {
if ($file_error === 0) {
if ($fiel_size <= 5000000) {
// $file_name_new = $file_fname . uniqid('',true) . '.' . $file_ext;
$file_name_new = uniqid('',true) . '.' . $file_ext;
$file_destination = '/uploads' . $file_name_new;
// echo $file_destination;
if (move_uploaded_file($file_tmp, $file_destination)) {
echo "Cv uploaded";
}
}
}
}
}
推荐答案
我尝试了相同的代码,并且对我有用.我为您做了一些更改.
I have tried the same code and it works for me. I have made some changes for you.
<form method="POST" enctype="multipart/form-data">
<label for="">Upload Your Cv</label><input type="file" name="file">
<input type="submit" name="upload" value="upload">
</form>
此后,您无需重定向页面;相反,您可以在</form>
After that you don't need to redirect the page; instead you can use this, below the </form>
if(isset($_REQUEST["upload"]))
{
if (isset($_FILES['file'])) {
$file = $_FILES['file'];
// print_r($file); just checking File properties
// File Properties
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];
// Working With File Extension
$file_ext = explode('.', $file_name);
$file_fname = explode('.', $file_name);
$file_fname = strtolower(current($file_fname));
$file_ext = strtolower(end($file_ext));
$allowed = array('txt','pdf','doc','ods');
if (in_array($file_ext,$allowed)) {
//print_r($_FILES);
if ($file_error === 0) {
if ($file_size <= 5000000) {
$file_name_new = $file_fname . uniqid('',true) . '.' . $file_ext;
$file_name_new = uniqid('',true) . '.' . $file_ext;
$file_destination = 'upload/' . $file_name_new;
// echo $file_destination;
if (move_uploaded_file($file_tmp, $file_destination)) {
echo "Cv uploaded";
}
else
{
echo "some error in uploading file".mysql_error();
}
//
}
else
{
echo "size must bne less then 5MB";
}
}
}
else
{
echo "invalid file";
}
}
}
请注意,上传文件夹必须与文件存储在同一目录中.
Note that the upload folder must be in the same directory as where you store the file.
这篇关于php文件上传错误警告move_uploaded_file无法打开流权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!