Jump to content

Upload files


MarcinUK
Go to solution Solved by Ch0cu3r,

Recommended Posts

Good afternoon,

I wrote a script for uploading files to ftp server. When I lunch this on local server(wamp) it does upload files into ftp server.

When I run the same script on my host provider(iPage) it doesn't upload files. Any advices?

Have a look at the code please.

 

form

<code>

<form enctype="multipart/form-data" action="upload.php" method="post">
    <table >

        <tr>
            <td>

            <input name="userfile" type="file">
             
            </td>                
        </tr>                

        <tr>        
            <td >
            <input type="Submit" value="Add file">
            </td>        
        </tr>

    </table>
</form>

</code>

 

upload.php

<code>

<?php
######################################################################
/*
For remote servers
*/
ini_set("max_execution_time", 100000000000);  // execution time must be bigger for larger files
$file = basename($_FILES['userfile']['name']);


//$remote_file = "/home/users/web/b1729/ipg.marcinkopecnet/remote_upload/$file";
$remote_file = "/remote_upload/$file";

/*
Define ftp server connection
*/
$ftp_server = "right_server";
$ftp_user_name = "right_username";
$ftp_user_pass = "right_password";

// set up basic connection
$conn_id = ftp_connect($ftp_server, 21) or die ("Cannot connect to host");

// turn passive mode on
ftp_pasv($conn_id, true);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("Cannot login");

// upload a file
if ($upload = ftp_put($conn_id, $remote_file, $_FILES['userfile']['tmp_name'], FTP_BINARY))
    {
    // check upload status:
    print (!$upload) ? 'Cannot upload' : 'Upload complete';
    print "\n";    
    
    //echo "successfully uploaded $file\n";
    }
else
    {
    echo "There was a problem while uploading $file\n";
    }

// close the connection
ftp_close($conn_id);
######################################################################
?>

</code>

Edited by MarcinUK
Link to comment
Share on other sites

"The script doesn't upload files" is a bit vague, don't you think? Have you turned on error reporting? What error messages do you get then?

 

Also, do you realize that this script has no protection whatsoever? It uploads any file to any location, which means you might as well print your FTP credentials on the screen.

Link to comment
Share on other sites

"The script doesn't upload files" is a bit vague, don't you think? Have you turned on error reporting? What error messages do you get then?

 

Also, do you realize that this script has no protection whatsoever? It uploads any file to any location, which means you might as well print your FTP credentials on the screen.

I turned on error reporting and server doesn't report anything. According to if,else statesment script returns "There was a problem while uploading $file\n".

That's true the script hasn't any protection but I want to let admin to upload any files to the selected location($remote_file = "/remote_upload/$file";). My colegue wants use form insted ftp client. That's only one reason of writing this script.

 

Interesting. You want to upload files into an ftp server but using an html form instead an ftp client ??? That sounds me like you want to watch a movie using a code editor ;)

I use ftp client but my colegue wants uplad files using form. He is just a user of the site.

 

If you are uploading the files to your site via HTML form then there is no need for the ftp functions. The file has already been uploaded when the form is submitted, you'd use move_uploaded_file to place the file where you want it to be saved.

This is a great solution. Thank. Now it works as I wanted.

Cheers. :)

Edited by MarcinUK
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.