PHP中的严格标准错误
我在这里看过类似的帖子,但没有找到解决方案。我得到了严格的标准:只有变量应该通过引用传递PHP中的严格标准错误,php,Php,我在这里看过类似的帖子,但没有找到解决方案。我得到了严格的标准:只有变量应该通过引用传递strtolower($file['name']),行上的错误。现在尝试了数小时寻找解决方案,但不知道如何更正。你能指出我哪里做错了吗 注:代码根据@Kolink的建议编辑如下: <?php require_once 'upload_config.php'; $mydirectory = myUploadDir(); $uploaded_file_counter = 0; $UploadLimit
strtolower($file['name']),
行上的错误。现在尝试了数小时寻找解决方案,但不知道如何更正。你能指出我哪里做错了吗
注:代码根据@Kolink的建议编辑如下:
<?php
require_once 'upload_config.php';
$mydirectory = myUploadDir();
$uploaded_file_counter = 0;
$UploadLimit = $_POST['counter'];
for ($i = 0; $i <= $UploadLimit; $i++) {
$file_tag = 'filename' . $i;
$filename = $_FILES[$file_tag]['name'];
if ($filename != null) {
$rand = time();
$str = "$rand$filename";
// set folder name in here.
$filedir = myUploadDir();
//change the string format.
$string = $filedir . $str;
$patterns[0] = "/ /";
$patterns[1] = "/ /";
$patterns[1] = "/ /";
$replacements[1] = "_";
$dirname = strtolower(preg_replace($patterns, $replacements, $string));
//end of changing string format
//checking the permitted file types
if ($check_file_extentions) {
$allowedExtensions = allowedfiles();
foreach ($_FILES as $file) {
if ($file['tmp_name'] > '') {
/*if (!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) */
if (!in_array(array_reverse(explode(".", strtolower($file['name'])))[0], $allowedExtensions)) {
$fileUploadPermission = 0;
} else {
$fileUploadPermission = 1;
}
}
}
} else {
$fileUploadPermission = 1;
}
//end of checking the permitted file types
if ($fileUploadPermission) {
if (move_uploaded_file($_FILES[$file_tag]['tmp_name'], $dirname)) {
echo "<p>"; ?>
<div><?php echo "<img style='height:100px;width:200px' src='$dirname'>"; ?></div> <?php
echo "</p>";
$uploaded_file_counter += 1;
}
}
}
}
if ($uploaded_file_counter == 0) {
echo "<br /> <b style='font-weight:bold;color:red'>Opss! Please select an image file<b>";
} else {
echo "<br /> <b>You request " . $i . " image files to upload and " . $uploaded_file_counter . " files uploaded sucessfully</b>";
}
?>
end
通过引用获取其参数,因为它通过移动其内部指针来修改原始数组
由于您似乎正在使用PHP 5.4,因此可以这样做来获取最后一个:
if( !in_array(array_reverse(explode(".",strtolower($file['name'])))[0],$allowedExtensions))
也就是说,为了提高可读性,最好分几个步骤进行:
$parts = explode(".",strtolower($file['name']));
$extension = $parts[count($parts)-1];
if( !in_array($extension,$allowedExtensions)) {
问题不在显示的代码中。向我们显示完整的堆栈跟踪。可能还有一个问题重复,如果我使用了End,则我无法打印/回显上载的所有文件(图像)。我在这里启用了多个上传。我已经在上面编辑了我的原始代码