Hello I have a write a code that upload image path into the database but the thing is it uploads the real path (C:/wamp/www/amref/images/student_profile/childbrah2.jpg) hence when I fetch the path form the database in order to display the image it gives me the error that the link is broken. I want to store only (images/student_profile/childbrah2.jpg).
The controller code:
$config['upload_path'] = '../images/student_profile/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = "2048000"; // Can be set to particular file size , here it is 2 MB(2048 Kb)
$config['max_height'] = "768";
$config['max_width'] ="1024";
$this->load->library('upload', $config);
if(!$this->upload->do_upload()){
echo '<h4 style="color: red;">
Failure! </h4>
<p style="color: red;">'.$this->upload->display_errors().'</p>';
} else {
$data_upload_files = $this->upload->data();
$image = base_url($data_upload_files['full_path']);
Yes. Because you inserting $config['upload_path'] = '../images/student_profile/', so path is C:/wamp/www/amref/images/student_profile/.
If you enter this as C:/wamp/www/amref/images/student_profile/ this will not work in your server. Because in your server there is no partition call C:.
So use your path as it is.
Edit
<?php
$old = 'C:/wamp/www/amref';
$fulpath = $old.'/images/student_profile/';
echo $fulpath;
Related
i have spend days trying to make image file i uploaded shows in its folder but when i upload an image file it goes to database but not displaying in folder i dont know why.
public function additems()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 106660;
$config['max_width'] = 1026664;
$config['max_height'] = 76668;
$this->load->library('upload', $config);
$this->load->view('templates/dashboard_head.php');
$this->load->view('admin/create_product');
$this->load->view('templates/admin_sidebar');
$this->load->view('templates/admin_footer');
$this->load->library('upload', $config);
if($this->input->post('submit'))
{
//get form's data and store in local varable
$name=$this->input->post('name');
$price=$this->input->post('price');
$description=$this->input->post('discription');
$code = $this->input->post('code');
$data = array('upload_data' => $this->upload->data());
$image = $_FILES['image']['name'];
//call saverecords method of Hello_Model and pass variables as parameter
$this->admin->insert_products($name, $price, $description,$code,$image);
echo "<script>
window.alert('added succesfully');
</script>";
}
The image gets assigned a temporary name on upload. You have to move it using something like this:
$uploadDirectory = './uploads';
move_uploaded_file( $_FILES['image']['tmp_name'], $uploadDirectory );
I am uploading a file on server and storing the its path in database in codeigniter, however i am after the upload i am not getting the correct path
The code that i have used is
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'doc|docx|pdf';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
$this->upload->do_upload('userfile');
$data = array('upload_data' => $this->upload->data());
$image_path = $data['upload_data']['full_path'];
I wish to save the path that i am getting in $image_path inside database.
Now the path that i get is something like this
/home/litehepn/public_html/project_name/uploads/xyz.docx
But the path that i want is
project_name/uploads/xyz.docx
Can anyone please tell how to get the correct path
This is the correct path. Because you have stored your files inside that home directory. But You can use chop($url,"/home/litehepn/public_html/"); for getting it.
Here is my controller code but only jpg and png file are uploaded I also changed it my process model.php also.
Is there any way to change it? And it doesn’t show any warning. You can check it from here but you need to register first...
public function saveTestimonial() {
$config['upload_path'] = './testimonial_photo/';
$config['allowed_types'] = 'gif|jpg|png|psd|zip|tif|ai|eps';
$config['max_size'] = '1024';
$config['max_width'] = '10240';
$config['max_height'] = '7680';
You should declare file upload like the below code. Since you are uploading images, docx, zip files you should not declare max_width and max_height. But you can change the max_size for the file.
$config['upload_path'] = 'testimonial_photo/';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->set_allowed_types('gif|jpg|png|jpeg|zip|pdf|doc|docx');
$this->upload->do_upload('filename_in_html_input')
<?php if($row->resumes != null){
$attachment= base_url().'uploads/resumes/'.$row->resumes;
echo '<a target="_blank" href="'.$attachment.'">
Show Resume</a>';
}
?>
Suppose, my file name is, my plan.pdf
so, on click of Show Resume then in url it's open like,
../uploads/resumes/my%20plan.pdf
in my resumes folder is store like my plan.pdf
there for 404 Page Not Found error is coming
i tried to using urlencode & urldecode, but it's not working.
I am not sure, but it might be the problem of white-space.
You may use trim() while inserting and retrieving time. or read PHP Manual
It won't work because of the space in the filename. I suggest that you use the Codeigniter upload class if you aren't already and remove any spaces from the file name before uploading.
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name'] = preg_replace('/\s+/', '', $filename); //Remove all whitespace
$this->load->library('upload', $config);
$this->upload->initialize($config);
Once the file has been uploaded you can get the name of the file by doing
$aUploadData = $this->upload->data();
$aUploadData['file_name'];
Then once you have that value you should insert it into your database because that way you will know that the value stored in the database will match the name of the file uploaded
Also as an extra check you should check to see if the file exists before linking to it
<?php if($row->resumes != null) {
if(file_exists(base_url().'uploads/resumes/'.$row->resumes)) {
$attachment= base_url().'uploads/resumes/'.$row->resumes;
echo '<a target="_blank" href="'.$attachment.'">Show Resume</a>';
}
}
?>
Hope that helps
I have the following model(codeigniter) code to upload image and thumbnail.
However the result of image path becomes, images/comfort_big.jpg and images/comfort_big.jpg.jpg.
The thumbnail image picks up the name of image and add .jpg.
I am uploading images/confort_thumb.jpg for thumb.
Can anyone tell me what's wrong please?
if ($_FILES){
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200';
$config['remove_spaces'] = true;
$config['overwrite'] = false;
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
if (strlen($_FILES['image']['name'])){
if(!$this->upload->do_upload('image')){
$this->upload->display_errors();
exit();
}
$image = $this->upload->data();
if ($image['file_name']){
$data['image'] = "images/".$image['file_name'];
}
}
if (strlen($_FILES['thumbnail']['name'])){
if(!$this->upload->do_upload('thumbnail')){
$this->upload->display_errors();
exit();
}
$thumb = $this->upload->data();
if ($thumb['file_name']){
$data['thumbnail'] = "images/".$thumb['file_name'];
}
}
}
I had a quick look at File Uploading Class in the user guide
In the preferences tables it states:
Note:The filename should not include a file extension.
So my guess is that you get the user to name the file
$config['file_name'] = "User defined";
or remove the extension programmatically. Since you know and list the extensions already you could do
$types = array(".gif",".jpg",".png");
$image['file_name'] = str_replace($types , "", $image['file_name'] );
Your problem is that when you create a thumb you are passing the full image.
So it will add another extension to it.
Use Below code to remove extension from file name.
<?php
$filename=$image['file_name'];
$file_name_with_dot = substr($filename,0, strrpos($filename, '.') + 1);
$only_file_name = substr($file_name_with_dot,0,strlen($file_name_with_dot)-1);
?>
Now pass this $only_file_name variable to your thumb function..
It will be better to use automatic thumb creation from main image.
Hope this will help for you.