- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我尝试在 CodeIgniter 中unlink
一个图像,但是 unlink
函数显示:
notice Undefined index: userfile
这是我的代码
<?php
function get_from_post(){
$data['logo_name'] = $this->input->post('logo_name',TRUE);
$data['logo_thumb'] = $_FILES['userfile']['name'];
return $data;
}
function deleteconf($data){
$data= $this->get_from_post();
$update_id=$this->uri->segment(3);
@unlink(base_url.'image/logo_thumb'.$logo_thumb);
$query= $this->_delete($update_id);
}
?>
最佳答案
the unlink function shows notice Undefined index:
userfile
确保您使用了 enctype="multipart/form-data"
上传表单的属性/值。
<form action="" method="post" accept-charset="utf-8" enctype="multipart/form-data">
来自MDN :
enctype
multipart/form-data
: Use this value if you are using an<input>
element with the type attribute set to "file".
如果您要使用 CodeIgniter form helper , 你可以使用 form_open_multipart()
功能:
This function is absolutely identical to the
form_open()
tag above except that it adds a multipart attribute, which is necessary if you would like to use the form to upload files with.
PHP unlink()
函数接受文件的路径作为第一个参数。不是 URL 地址。
base_url()
辅助函数 returns the URL address网站,which you've set在config.php
文件。
您必须使用服务器上文件的路径,如下所示:
unlink('/path/to/image/image_name.jpg'); // This is an absolute path to the file
您可以使用绝对 或相对 路径,但请注意相对路径 是相对于 index.php
文件。即如果image/
文件夹放在 index.php
旁边文件,你应该使用 image/image_name.jpg
作为文件路径:
unlink('image/image_name.jpg'); // This is a relative path to the file
关于php - 如何在 CodeIgniter 中取消链接(删除)图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21642525/
我是一名优秀的程序员,十分优秀!