Welcome Guest, Not a member yet? Register   Sign In
File uploads inquiry
#1

[eluser]stevefink[/eluser]
Hi all,

Hope everyone had a pleasant weekend.

I'm currently running an upload application based on SWFUpload, ( http://swfupload.mammon.se/ ) and I was curious how I can implement the native CI file upload handlers into my code. Currently I'm using something like this in my controller:

Code:
function upload()
    {
        if($_FILES) {
            set_time_limit(30); // This line sets the amount of time the script will execute for before it stops working. I've set this to 0 so there won't be any time-out errors.

            $uploadDir = "/Applications/MAMP/htdocs/f1auto_ci/uploads"; // Put in the directory that you will be uploading to. Don't forget the last '/'

            $filename = ereg_replace("[^A-Za-z0-9.]", "", $_FILES['Filedata']['name']); // Here I am taking the file name (accessed by $_FILES['Filedata']['name']) and I'm replacing any non alphanumeric characters. All that should be left is the file name, a dot and the extension.

            $uploadFile = $uploadDir . "/" . $filename; // This puts the directory and file name together in a variable. Handy for later on to keep your code easy to read.

            move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile); // This actually moves the file to the directory and file name specified by the $uploadFile variable.

            chmod($uploadFile, 0777); // Here I'm changing the permissions of the file so that we can do other things to it later on, like re-sizing images or being able to delete it from your FTP client.
            
            echo("This is complete!");
        }

Is it alright if I stick with this? The code is so customized, that I'm having difficulty incorporating it the CI way. I have a demo of this application up at http://devel.phpgeek.org/console/addvehicle/photos .. if you want to try to upload multiple files, they'll get deleted on the server right after. Just so you can get an idea of what I'm doing. :-)

Thanks,

- sf
#2

[eluser]ssjcory[/eluser]
I'm not sure what CI is but I do have a suggestion. Put your comments above each line of code. It makes them more readable then being off to the side. Especially if your project is thousands of lines.
-Cory
#3

[eluser]Michael Wales[/eluser]
CI is Code Igniter - the topic of this forum.
#4

[eluser]ssjcory[/eluser]
Ah lol i thought it was just a fancy name hehe :-)
Thx.




Theme © iAndrew 2016 - Forum software by © MyBB