How to add image upload to my CRUD |
[eluser]sb05[/eluser]
Hi Guys, I am really struggling adding an image upload in my form. WIth this code below I get an error: undefined variable full_file_path. But I did define it, so I don't know what's wrong. Hope you guys can help out. Here is my controller: articles.php Code: function add(){ And my view: articleEdit.php Code: <form method="post" action="<?php echo $action; ?>"> My database is working. Without the file upload everything works fine, and when I add the file upload code, the only thing my code does is store the name of the image in the image_url field in the database. But the image does not get uploaded in my uploads folder. Hope you guys can help!
[eluser]Cristian Gilè[/eluser]
Hi sb05, from codeigniter guide: Quote:Create a folder at the root of your CodeIgniter installation called uploads and set its file permissions to 777. Uploads folder should be in the root not inside application. Cristian Gilè
[eluser]sb05[/eluser]
Yes I forgot to tell that. I already did that, and it also didn't work ![]()
[eluser]Cristian Gilè[/eluser]
To define $full_file_path you can do this: Code: $full_file_path = $upload_data['full_path']; but this is not the issue. Are you sure the uploads folder is in the right place? Uploads folder should be at the same level of index.php file and check for 777 permissions. Cristian Gilè
[eluser]sb05[/eluser]
Yes, I did. I actually double checked again. By the way I'm doing this on the mac. So I changed the permissions again to the uploads folder to 777. And it again says it has all the writing permissions. So I am really confused. This is driving me nuts. This app has to be ready in a couple of days for school, but nobody there knows a thing about CodeIgniter ![]() I have double checked everything, and I really can't see it.
[eluser]Unknown[/eluser]
What kind of server software are you using? Running locally? I had problems with permissions on MAMP (for mac). I use BatchMod to set my permissions now. It works better. If you run it locally: Make sure that the server has the permissions of 777 and not"you" as the OS user.
[eluser]Cristian Gilè[/eluser]
By default the upload routine expects the file to come from a form field called userfile, and the form must be a "multipart type. Change your form tag to: Code: <form method="post" action="<?php echo $action; ?> enctype="multipart/form-data" /> and change your input file to: Code: <input type="file" name="userfile" class="text" value="<?php echo $this->validation->image_url; ?>"/> Cristian Gilè
[eluser]sb05[/eluser]
Sorry for the late response guys, I was messing with my code here and there and it got all spaghetti all of a sudden ![]() @Algoritm Yes apparently MAMP was the problem that the image did not upload. When I ran it on my remote server, the uploading went well. However only the image went to my folder but the other textfields did not go to my database. But Cristian solved that with his last post ![]() @cristian I already tried the enctype once but it also didnt work. However in the input type name="" . I had image_url instead of userfile. But now with the enctype AND name="userfile", it worked! So thank you guys very much for the help:-D |
Welcome Guest, Not a member yet? Register Sign In |