我已经写了这个php处理程序,用于将文件上传到我的服务器。它在我进行一些测试时起作用,现在它突然出现错误。
这是错误:
警告:implode():参数必须是第7行的/path/to/file/upload.php中的数组
警告:implode():参数必须是第12行的/path/to/file/upload.php中的数组
这是我的经纪人:
<?php
error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
$target_dir = "uploads/";
$target_file = $target_dir . implode( $_FILES[ "upload" ][ "name" ] );
$uploadOk = 1;
$FileType = ( pathinfo( $target_file, PATHINFO_EXTENSION ) );
// Check file size
if ( implode( $_FILES[ "upload" ][ "size" ] ) > 500000000000 ) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if ( $FileType != "zip" ) {
echo "Sorry, only ZIP files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ( $uploadOk == 0 ) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if ( move_uploaded_file( implode( $_FILES[ "upload" ][ "tmp_name" ] ), $target_file ) ) {
echo "The file " . implode( $_FILES[ "upload" ][ "name" ] ) . " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
这是我的表格:
<form action="upload.php" method="post" enctype="multipart/form-data">
<input name="upload" type="file"/>
<input type="submit" value="Upload"/>
</form>
我无法理解当我不碰它时如何停止工作。任何想法为什么它不起作用?
答案 0 :(得分:1)
试试这个。
删除了不应该存在的所有内爆。
<?php
error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
$target_dir = "uploads/";
$target_file = $target_dir . $_FILES[ "upload" ][ "name" ] ;
$uploadOk = 1;
$FileType = ( pathinfo( $target_file, PATHINFO_EXTENSION ) );
// Check file size
if ( $_FILES[ "upload" ][ "size" ] > 500000000000 ) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if ( $FileType != "zip" ) {
echo "Sorry, only ZIP files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ( $uploadOk == 0 ) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if ( move_uploaded_file($_FILES[ "upload" ][ "tmp_name" ] , $target_file ) ) {
echo "The file " . $_FILES[ "upload" ][ "name" ] . " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
答案 1 :(得分:0)
$ _ FILE ['upload'] ['name']是一个字符串你不能内爆它
如果你想要它的名字你不必破坏它只需使用
fileName = $_FILE['upload']['name'];
$targDir = "uploads/";
$tagFile = $tagDir.$fileName
会这样做