unlink 函数显示通知未定义索引:userfile
上传表单,使用multipart/form-data
确保您已经使用过enctype="multipart/form-data"
您的上传表单的属性/值。
<form action="" method="post" accept-charset="utf-8" enctype="multipart/form-data">
来自MDN https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-enctype:
enctype
multipart/form-data
:如果您使用的是<input>
type 属性设置为“file”的元素。
如果您要使用 CodeIgniter表单助手 http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html,你可以使用form_open_multipart()
功能:
该功能与form_open()
上面的标签
除了它添加了一个多部分属性,如果您
想要使用表单来上传文件。
删除文件,文件路径与 URL 地址
PHP unlink() https://www.php.net/unlink函数接受Path文件的作为第一个参数。不是网址地址.
The base_url() https://github.com/EllisLab/CodeIgniter/blob/2.1-stable/system/helpers/url_helper.php#L64-L68辅助函数返回 URL 地址 https://github.com/EllisLab/CodeIgniter/blob/2.1-stable/system/core/Config.php#L282该网站的,你设置的 https://github.com/EllisLab/CodeIgniter/blob/2.1-stable/application/config/config.php#L17 in the config.php
file.
您必须使用服务器上文件的路径,如下所示:
unlink('/path/to/image/image_name.jpg'); // This is an absolute path to the file
你可以使用Absolute or Relative路径,但请注意相对路径 是相对于 the index.php
文件。即如果image/
文件夹放在旁边index.php
文件,你应该使用image/image_name.jpg
作为文件路径:
unlink('image/image_name.jpg'); // This is a relative path to the file