我正在尝试将图像插入到我的 MySQL 服务器中。我做了一些研究,看起来最好的方法是通过LOAD_FILE(). 但是,LOAD_FILE()始终返回 null。我知道有 4 个条件LOAD_FILE():
我目前正在使用:
select LOAD_FILE('/Users/pricedb/Desktop/FolderName/imageName');
Run Code Online (Sandbox Code Playgroud)
它返回NULL
我已经确认所有权限都授予用户。文件必须位于服务器主机上是什么意思?服务器正在我的本地计算机上运行,并且文件位于那里,这是否意味着我很擅长?
任何建议将不胜感激,我不知道为什么它没有返回值。
我有一个Android应用程序,其中管理员用户可以创建普通用户帐户,其中管理员用户可以选择普通用户的照片来创建帐户.在存储普通用户名,年龄ETC之前,情况正常.但是当我想将普通用户的图像存储到数据库时出现问题.我使用Wamp服务器作为后端数据库.
你能告诉我如何在WAMP服务器中存储图像以及如何再次检索它以便我可以在Android活动上显示.
功能如,管理员用户登录---->创建普通用户 - >选择图像 - >存储在数据库中.
普通用户登录--->从数据库中检索图像 - >在Android活动中查看图像.
我的客户在php + mysql中创建了一个脚本,可以直接在数据库中保存图像,每个图像都有这样的URL:www.example.com/image.php?id = 421
在您看来,这是一个非常错误的解决方案?我应该重建所有网站吗?
每天大约有1000次访问,数据库中有大约600张图像.
我正在使用WAMP服务器,我想使用CI在数据库中上传图像.数据库中的图像变量是blob数据类型.我的问题如下:
1)如何存储图像而不是文件名以及我应该使用哪些数据类型?
2)如何从数据库中检索图像?
我的控制器代码:
<?php class Image_control extends CI_Controller{
function index()
{
//$this->load->view('image_view');
//$this->Image_model->do_upload();
$data['images']=$this->Image_model->get_images();
$this->load->view('image_view',$data);
}
function do_upload()
{
$config = array(
'allowed_types' => 'jpg|png|bmp',
'upload_path'=>'./images1/',
'max_size'=>2000
);
$this->load->library('upload',$config);
if (!$this->upload->do_upload()) {
$errors[]=array('error'=>$this->upload->display_errors());
$this->load->view('image_view',$errors);
}
$image_path=$this->upload->data();
$file_name=$image_path['file_name'];
$config = array(
'a_name' => $this->input->post('a_name'),
'a_details'=>$this->input->post('a_info'),
'a_photo'=>$file_name
);
$insert=$this->db->insert('animalstore',$config);
return $insert;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我的模特的代码:
<?php class Image_model extends CI_Model {
function get_images()
{
$query = $this->db->get('animalstore');
if($query->num_rows > 0 )
{
foreach($query->result() as $rows)
{
$data[] = $rows;
}
return …Run Code Online (Sandbox Code Playgroud) 每当我点击“提交”按钮时,我都会收到此错误。其他所有内容都提交给数据库,只有图像没有提交。警告:file_get_contents():文件名不能为空任何想法?这是我的代码。
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) …Run Code Online (Sandbox Code Playgroud) mysql ×6
php ×4
image ×3
android ×1
codeigniter ×1
database ×1
file ×1
html5 ×1
null ×1
wampserver ×1