Welcome Guest, Not a member yet? Register   Sign In
ftp - upload via a web form
#1

[eluser]bugboy[/eluser]
I've looked all over and in the user guide but i can't find an answer.

Using the CI ftp class can i use it to upload a file using a web form?

If so how as there is no mention of it. Help please.

I need to upload video files.

do i need to roll my own?

cheers
#2

[eluser]tonanbarbarian[/eluser]
i do not see how you could use the ftp class to upload a file from a clients machine to the server
the upload action has to happen from the client not from the server so the could would have to be running on the clients pc
requiring them to have php installed as well as CI etc.

if you want something to be able to ftp a file from a client pc to your server you should look at a java applet or maybe a flash (not sure if flash can do that but i assume it can)
#3

[eluser]bugboy[/eluser]
i see

i found this on the php site where they use a webform. so i wondered if i could extend the ftp class.

Code:
<?php  
$myFile = $_FILES['file']; // This will make an array out of the file information that was stored.
    $file = $myFile['tmp_name'];  //Converts the array into a new string containing the path name on the server where your file is.
    $myFileName = $_POST['MyFile']; //Retrieve file path and file name  
    $myfile_replace = str_replace('\\', '/', $myFileName);    //convert path for use with unix
    $myfile = basename($myfile_replace);    //extract file name from path
    $destination_file = "/".$myfile;  //where you want to throw the file on the webserver (relative to your login dir)
    // connection settings
    $ftp_server = "127.0.0.1";  //address of ftp server (leave out ftp://)
    $ftp_user_name = ""; // Username
    $ftp_user_pass = "";   // Password
    $conn_id = ftp_connect($ftp_server);        // set up basic connection
    // login with username and password, or give invalid user message
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<h1>You do not have access to this ftp server!</h1>");
    $upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);  // upload the file
    if (!$upload) {  // check upload status
        echo "<h2>FTP upload of $myFileName has failed!</h2> <br />";
    }
/*
    // try to delete $file
    if (ftp_delete($conn_id, $destination_file)) {
        echo "$destination_file has been deleted!\n";
    } else {
        echo "Could not delete $destination_file!\n";
    }
*/
ftp_close($conn_id); // close the FTP stream
}
?&gt;
&lt;form name="form" enctype="multipart/form-data" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="POST" &gt;
Please choose a file: &lt;input type="file" name="file" accept="text/plain" onChange="MyFile.value=file.value"&gt;
&lt;input name="MyFile" type="hidden" id="MyFile" tabindex="99" size="1" /&gt;
&lt;input type="submit" name="submit" value="upload" style="vertical-align:middle"/&gt;<br/><br/>
&lt;/form&gt;
#4

[eluser]tonanbarbarian[/eluser]
ok what that code is doing is taking the file that was already uploaded via http and ftping it back to the server
the reason to do this is so that the permissions on the file can be set exactly for the user who owns the site
some CMSes do this
mostly it is because the webserver, such as apache, ususally runs under a different user account than the owner of the site and so often the permissions are such that after the file has been uploaded the account owner cannot delete the files etc because the permissions are not correct
#5

[eluser]bugboy[/eluser]
oh i see.

so you can't technically upload like real upload using ftp. all you can do is move as such?

i need to be able to upload files as large as 50mb i thought yeah ftp would do the trick. whats this flash thing?

many thanks
#6

[eluser]tonanbarbarian[/eluser]
you could get a flash or java applet to do the ftp for you
i definately know that there are java applets that will ftp files from the clients pc to your server
am not 100% sure that any flash exists to do the same but it might
PHP can be used to upload 50Mb files, you just need to config PHP and your webserver to allow it
i do not recommend it for files that large however
mostly because the java applet has ftp resume so that the file can be stopped and started where as a http upload via php would not be able to do that
#7

[eluser]bugboy[/eluser]
it might be easier to use youtube and transfer the video across?
#8

[eluser]bugboy[/eluser]
any recommendations for the java applet? with pref for free.
#9

[eluser]Sean Murphy[/eluser]
If you explain a little more why need to have a file FTPed to a server from a web form, it would help to suggest the best approach.

As long as there is nothing preventing you from uploading 50MB files to your webserver temporarily, you could certainly use the approach taken in the example you posted above using the Upload and FTP libraries (no modification needed). But there's really no reason take this approach unless you need the files stored on a server other than the one your application is hosted on.

If file upload size is the only thing you're concerned about, use the suggestions on this page: http://www.radinks.com/upload/config.php

If you still want to use a Java applet, someone commented about using JUpload here: http://us.php.net/manual/en/features.fil....php#60349
#10

[eluser]bugboy[/eluser]
hello thanks for replying.

i need to upload a video files that maybe sometimes over 10mb up to 50mb and the server only allows a post max of 8mb

I'll look into the suggestions you made but i hope that makes more sense of what i'm after.

Cheers




Theme © iAndrew 2016 - Forum software by © MyBB