文件名不能为空 [英] Filename cannot be empty

查看:213
本文介绍了文件名不能为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次点击提交按钮时,都会出现此错误.其他所有内容都提交给数据库,只有图像不提交. 警告:file_get_contents():文件名不能为空 任何的想法?这是我的代码.

I get this error everytime i hit the submit button. Everything else is submitted to the database, only the image isn't. Warning: file_get_contents(): Filename cannot be empty Any idea? Here is my code.

if(isset($_POST['consultationbutton'])){        
    $image = addslashes(file_get_contents($_FILES['selectedfile']['tmp_name'])); //SQL Injection defence!
    $image_name = addslashes($_FILES['selectedfile']['name']);
    $checkedcondition = implode(",",$_POST['skincondition']);
    $checkedproduct = implode(",",$_POST['skincareinuse']);
    $consultquery="INSERT INTO counsel(nric,dateconsulted,editableface,skincarecurrentlyinuse,skincondition,imagename) VALUES('132','$_POST[storedate]','{$image}','$checkedproduct','$checkedcondition','{$image_name}')";
    mysqli_query($dbconn,$consultquery);
   // mysqli_escape_string($dbconn,$image);
    echo $checkedcondition;
    echo $checkedproduct;
}   

<form action="BAConsult.php" enctype="multipart/form-data" method='post'>
<img id="customerface" src="#" alt="your image" class ="consultimg"></img>
 Select a file to upload: <input type="file" name="selectedfile" onchange="readURL(this);">
<input type='submit' name='consultationbutton' class='consultationbutton' value='Complete Consultation' onclick='submitclick();'>
</form>

<script>
function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#customerface')
                .attr('src', e.target.result)
                .width(400)
                .height(400);
        };

        reader.readAsDataURL(input.files[0]);
    }
}
</script>

推荐答案

$_FILES数组中,您说的是[name]=>DSC_0770.JPG[type]=> [tmp_name]=>[error]=>1[size]=>0

如果未提供tmp_name,则表示文件未上传.

If tmp_name is not given, that means the file was not uploaded.

根据1 >上载错误消息解释页面,这意味着:上载的文件超出了 upload_max_filesize 指令.

The error you're given is 1, and according to the upload error messages explained page this means: that the uploaded file exceeds the upload_max_filesize directive in php.ini.

您可以执行以下操作来解决此问题.

You can do the following to fix this.

  • 找到您的php.ini文件,并增加upload_max_filesize的大小.
  • 在脚本开头使用ini_set('upload_max_filesize', '20M');或您想要的任何大小.
  • 在上传之前压缩图像.
  • Find your php.ini file and increase the size of upload_max_filesize.
  • Use ini_set('upload_max_filesize', '20M'); or whatever size you want at the start of your script.
  • Compress your images before uploading.

这篇关于文件名不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆