Jump to content

Upload files


MarcinUK

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>

Link to comment
https://forums.phpfreaks.com/topic/290863-upload-files/
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
https://forums.phpfreaks.com/topic/290863-upload-files/#findComment-1490015
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. :)

Link to comment
https://forums.phpfreaks.com/topic/290863-upload-files/#findComment-1490039
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.