the unlink function shows notice Undefined index: userfile
The upload form, using multipart/form-data
Make sure you've use enctype="multipart/form-data"
attribute/value for your upload form.
<form action="" method="post" accept-charset="utf-8" enctype="multipart/form-data">
From the MDN:
enctype
multipart/form-data
: Use this value if you are using an <input>
element with the type attribute set to "file".
If you're going to use CodeIgniter form helper, you could use form_open_multipart()
function:
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.
Deleting files, File path vs URL address
PHP unlink()
function accepts the Path of the file as the first argument. Not the URL Address.
The base_url()
helper function returns the URL address of the site, which you've set in the config.php
file.
You'll have to use the path of the file on your server, as follows:
unlink('/path/to/image/image_name.jpg'); // This is an absolute path to the file
You could use an Absolute or Relative path, but note that the relative path is relative to the index.php
file. i.e. If the image/
folder is placed beside index.php
file, you should use image/image_name.jpg
as the file path:
unlink('image/image_name.jpg'); // This is a relative path to the file
$logo_thumb
come from? I can't see where you've assigned the value. – Continuatebase_url
? Is that the CodeIgniterbase_url()
? – Continuate