本文介绍了上传的服务器映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?php
$target_path1 = "uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path1 = $target_path1 . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path1))
{
echo "The first file ". basename( $_FILES['uploaded_file']['name'])."has been uploaded.";
} else {
echo "There was an error uploading the file, please try again!";
echo "filename: " . basename( $_FILES['uploaded_file']['name']);
echo "target_path: " .$target_path1;
}
?>
这有3个错误
注意:未定义指数:uploaded_file在D:\\ anddev \\项目\\网络\\ upload_test \\ upload_media_test.php第5行
注意:未定义指数:uploaded_file在D:\\ anddev \\项目\\网络\\ upload_test \\ upload_media_test.php第6行
Notice: Undefined index: uploaded_file in D:\anddev\project\web\upload_test\upload_media_test.php on line 6
注意:未定义指数:uploaded_file在D:\\ anddev \\项目\\网络\\ upload_test \\ upload_media_test.php第11行
Notice: Undefined index: uploaded_file in D:\anddev\project\web\upload_test\upload_media_test.php on line 11
我该如何解决这个问题code?
How do I fix this code ?
推荐答案
始终添加检查,以确保你实际上得到的东西,
Always add check to make sure you are actually getting something,
您可以使用试试吧像这样的:
You can make use of is_uploaded_file Try it like this:
<?php
if(is_uploaded_file($_FILES['uploaded_file']['tmp_name']){
//we got something, set it up
$target_path1 = "uploads/";
$file = basename( $_FILES['uploaded_file']['name']);
$full_path = $target_path1.$file;
//perform the upload
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $full_path)) {
echo "The first file ".$file." has been uploaded.";
} else {
echo "There was an error uploading the file, please try again!";
echo "filename: " . $file;
}
}else{
echo "Nothing was uploaded";
}
?>
这篇关于上传的服务器映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!