Tutorial Details
- Technology: CodeIgniter
- Difficulty: Intermediate - Advanced
In today’s episode, we are going to be working with several helper functions, related to files, directories, and downloads. We are going to learn how to read, write, download files, and retrieve information about both files and directories. Also at the end we will build a small file browser that utilizes jQuery as well.
Catch Up
- Day 1: Getting Started With the Framework
- Day 2: Database Selecting Methods
- Day 3: Sending Emails
- Day 4: Newsletter Signup
- Day 5: CRUD
- Day 6: Login
- Day 7: Pagination
- Day 8: AJAX
- Day 9: File Uploading and Image Manipulation
- Day 10: The Calendar Library
- Day 11: File and Directory Operations
Day 11: File Operations
Get the Flash Player to see this player.


RoyalSlider – Touch-Enable ... only $12.00 
Thank you!
Burak
Codeigniter rulez!!
seriyi devam ettirdiğin için teşekkürler.
-
thanks
@ 23:50 the video stop… :(
thanx!
Thanks for continuing the series.
The video stops around the 23min mark, just as things start to get interesting.
Will try again later.
It’s stopping around the 23:45 mark for me. Going to try another browser.
Video file is fixed. Must have stumbled when we copied it over to our server. :)
Jeff Ur gravatar also stumbled :)
Really nice tutorial! I really like CI but prefer Kohana, which is based on CI but is built in PHP5.
CI 2.0 will be based on PHP5
[from: http://www.michaelwales.com/2010/03/codeigniter-2-0-and-mercurial-transition/
Phil Sturgeon and Elliot Haughin have provided their run-downs of CodeIgniter changes as well. One of the biggest changes I missed was the fact that CodeIgniter 2.0.0 functionality is not guaranteed to work in PHP4 and by CodeIgniter 2.1.0, legacy features will no longer be guaranteed to work in PHP4 either.
CI already runs perfectly on PHP5… running on PHP4 is only an option
@Erik
Well – not realy. If something is backward compatible with PHP4 then it’s not full PHP5 withh all its futures.
PHP5 is compatible (in most) with PHP4 and that’s why CI works on it.
Anyone knows when CI 2.0 is coming?
CI rocks!
Thanks for the series but where to download this part??
i want to download this part too =/
i was downloading the other parts to view ( my net is too slow to view online ) but this one isn’t on the list where i was downloading ( http://nettuts.blip.tv/ )
can you upload this video there please??
i love this series and would like to watch this too =`(
http://nettuts.s3.amazonaws.com/598_ci11/ci_from_scratch_day11_files_directories_downloads.mp4
It stops at 23:50 and tried 3 different browsers safari, chrome, ie.
The cache was cleared if needed and I waited until the entire video was cached before starting the video around 22:00 mark.
Anyone else having problems?
Still have problems with this one. The page says I need to get flash player but haven’t had a problem with any of the other ci from scratch ones.
I had this problem a while back with some of the premium dl’s. It was just random ones.
I found that when I have this problem I can use downloadthemall addon and they will download fine.
Try the link above with downloadthemall. It works
Great series of post i am getting started to learn codeigniter. thanks for all
is there a ci version of mkdir. I’ve been having some weird issues with mkdir since I upgraded my local server
same problem as Dave. Like a 25cent peep show just as it gets good the curtain draws. Where do I put my quarter in for more……
I’ve been watching/reading all of the tutorials and I’m wondering how you make each page link like this:
home – example.com/
news – example.com/news/
blog – example.com/blog
All of this “example.com/index.php/site/news” stuff is cool, but I know that not one of my clients will want their links to look like that!
You can remove it with the help of a .htaccess file. More info here:
http://codeigniter.com/wiki/mod_rewrite/
Nice job Burak! I really like your tutorials you explain things very well. What font is it you are using in aptana?
It’s Consolas
where to download video.
Here is the link, it’s fixed now.
http://nettuts.s3.amazonaws.com/598_ci11/ci_from_scratch_day11_files_directories_downloads.mp4
Great,
still learning CI.
Thanks for this
Fantastic, thank you!
Hey,
this podcast isnt available on itunes yet! Can somebody take care of that?
Also I would like to see the CodeIgniter From Scratch Day 5 CRUD episode on itunes Podcasts! It still isnt there : (. Dont know if that’s possible, but I do hope so.
Love what’s been done with the site!!!
Nice work Burak on this screencast!
Thank you Burak. Files were always a ball of confusion for me, now I see plenty of places i could use the the codeigniter functions with them
Well done.
Nice Post. Thanks…Codeigniter is The Best Framework. Yeah..
btw, where net.tutplus.com mobile version..???
Just a comment: it seems that DIRECTORY_SEPARATOR is not necessary for specifying portable file names. http://us2.php.net/manual/en/ref.filesystem.php#73954
Yeah, if you use forward slash, paths still work on Windows for example.
But I encountered some strange behavior when using some CI functions. Seems like it’s because CI’s code references DIRECTORY_SEPARATOR while dealing with file paths. They do things like trimming the slash at the end of a path, or split the path string into pieces at the slashes etc… And since that constant translates into backslash (on windows), and if you passed forward slash to a CI function, sometimes it won’t work.
i really love this CI series. Thanks @Jeffrey and @Burak i’ve learned allot thanks to this series.
Hello, very useful lesson! Could you tell me what Font enjoy, like a mac? I like and I want to have it.
The font I use is Consolas.
Out of curiosity, why didn’t you use APPATH for the path to the file location? Is there some reason for files that that constant might not be useful?
APPPATH is for the application folder, and BASEPATH is for the system folder. Just a matter of preference.
Great one, thanks @Burak Guzel, its really nice to see more tutes on nettuts, CodeIgniter really an easy framework and why not kohana tuts?
I would like to get into Kohana too, but CodeIgniter is great for beginners. Has good documentation and big community.
Great information.
Great tutorial Burak!
I have one little suggestion for next tutorials.
To print out arrays in a “human readable” format try using the second parameter of print_r function ( default is false ):
echo ” . print_r($array, true) . ”;
This way you will see the array as you see it when viewing page source code when using print_r without the second parameter.
—
What about some XML-RPC for next chapter?
Cya!
HTMLEntities messed up my last comment, inside those quotes there’s a PRE tag.
Sorry.
süpersin Burak, eline sağlık.
sorry guys, i just want to thank to Burak in our mother language ;)
I tried to modify this script to fit my needs but i have run into some problems, i think it is related to my limited Javascript knowledge.
In the “foreach”-loop i want to add more things to the click event-listener. So i modified the call to look like this:
span.click(function (){
MyFunc($(this), files[x]);
});
but this didn’t really do what i wanted… I want to pass the remaining content of files into the function, but it seems like the content is beeing parsed when the button is clicked (and then files[x] is undefined).
Can you understand my problem or do i need to be more specific?
//Moppa
HI,
thanks for all great tuts
but about the download link, this is impossible for me and also some of my firends ( i asked them ) to download it, could you please upload it as previous days or somewhere else like rapidshare ?
Thanks again
Just 2 hours after commenting , i could download it
thanks
When will be next tutorial?
the things becomes intersting now,
please burak go ahead..
Burak how are you getting the nice code CI completion in Aptana? That’s one small annoyance about CI, that no IDE will do code completion — I have Komodo and use mostly Nusphere, neither does completion for CI. Are you using the older php plugin or somehow getting the Eclipse PDT to behave? Maybe an idea for another CI tut.
I am having a problem with the javascript. I use an external file and when I type in the
var files = ;
I get an error
Line: 36
Character: 17
Code: 0
Error Message: Syntax error
URL: http://localhost/nettuts.com/js/scripts.js
Can someone tell me why it works in the actual file but not in an external js file?
Here is the actual code
// Directory Map
var files = ;
var file_tree = build_file_tree(files);
file_tree.appendTo(‘#files’);
function build_file_tree(files) {
var tree = $(”);
for (x in files) {
if (typeof files[x] == “object”) {
var span = $(”).html(x).appendTo(
$(”).appendTo(tree).addClass(‘folder’)
);
var subtree = build_file_tree(files[x]).hide();
span.after(subtree);
span.click(function() {
$(this).parent().find(‘ul:first’).toggle();
});
} else {
$(”).html(files[x]).appendTo(tree).addClass(‘file’);
}
}
return tree;
}
Nice n easy………exactly what I was looking for !!
After playing around for a while I still can’t find a way to get the file URLs into my page to create download links like Burak suggested.
I tried the function get_dir_file_info(BASEPATH) and successfully got the raw output of that into my HTML, but there is a major problem with that function: because it uses the filenames as array indexes, data is overwritten when you have duplicate filenames in the tree (e.g. index.html in many directories).
Does anybody know what other function or method I should be using in CodeIgniter to get the paths for all my files into an array I can use to build my hrefs? Or do I have to do all the recursion and array-building manually (thus negating the need for CI)?
Hello there! nice series of tutorials on this framework, when I stumbled upon CodeIgniter I thought “who the hell would want a framework for php, in which you have to adapt to a kind of object oriented scripting language ?” then I saw this, I’m downloading all episodes as I’m writing this, and have one request if it can be fulfilled: how about a clean Url tutorial? I’ve read the mod_rewrite on CodeIgniter’s wiki, but it’s much better to have one of you guys who understand this things to explain on a video tutorial.
peace & thanks for opening my eyes
Why are you putting all the javascript in the body. Surely it should go in the head.
hi i got very good idea of codeIgniter from these tutorial .Burak should try to cover more database stuff in examples
How can we use the php function if the javascript and css are on an external file ?
quick question.
First thank you very much for this. I am trying to create something almost exactly to what this explains.
second How would i go about turning the files into hyperlinks to download. I have been trying to use the force_download and download function in the controller from my view but cant seem to get it to work. has anyone else been able to get this to turn into a download hyperlink for the files?
Hello Burak,
I have thoroughly enjoyed your CI lessons. I’ve learned and continue learning so much.
Could you please tell me how you get html:5 to write the html stuff for you?
I have the newest version of Aptana and I’m a new Aptana user.
The video is down. can you guys please re-upload it.
Hi all! for some reason, the icons burak include in the images folder are not appearing when I call the ‘ display ‘ function, the other functions work perfectly. Image with output of ‘ display ‘ function http://imageshack.us/photo/my-images/163/screenshotur.png/
Also, I am using ubuntu, but I don’t think the problem is security related, because I can edit the hello.txt file(I set the permissions to read/write).
P.S. : Well structured lesson, Burak. Keep up the good work!