Solved

PHP Uploading to FTP server with video files

Posted on 2014-09-24
5
516 Views
Last Modified: 2014-09-24
Hi All,

I have an issue.  I can upload files to an FTP server just fine, but I cannot upload mp4 files and I am kind of new to PHP

The following is my code:

<?php

if(isset($_POST['start_upload']) && $_FILES['txt_file']['name'] != ""){

    $local_file = $_FILES['txt_file']['tmp_name']; // Defines Name of Local File to be Uploaded

    $destination_file = "/".basename($_FILES['txt_file']['name']);  // Path for File Upload (relative to your login dir)

    // Global Connection Settings
    $ftp_server = "172.30.1.39";         // FTP Server Address (exlucde ftp://)
    $ftp_user_name = $_POST['username'];  
    $ftp_user_pass = $_POST['pwd'];      
 if ($ftp_user_name != '' || $ftp_user_pass = '')
{
    // Connect to FTP Server
    $conn_id = ftp_connect($ftp_server);
    // Login to FTP Server
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

    // Verify Log In Status
    if ((!$conn_id) || (!$login_result)) {
        echo "FTP connection has failed! <br />";
        echo "Attempted to connection for user $ftp_user_name";
        exit;
    }

    $upload = ftp_put($conn_id, $destination_file, $local_file, FTP_ASCII);  // Upload the File

    // Verify Upload Status
    if (!$upload) {
        echo "<h2>FTP upload of ".$_FILES['txt_file']['name']." has failed!</h2><br /><br />";
    } else {
        echo "Success!<br />";
    }

    ftp_close($conn_id); // Close the FTP Connection
}
}
?>

<html>
    <head>
        <script type="text/javascript">
            window.onload = function() {
                document.getElementById("progress").style.visibility = "hidden";
                document.getElementById("prog_text").style.visibility = "hidden";
            }

            function dispProgress() {
                document.getElementById("progress").style.visibility = "visible";
                document.getElementById("prog_text").style.visibility = "visible";
            }

        </script>

    </head>
    <body>
        <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" enctype="multipart/form-data">
            Username:<br/><input type="text" name="username" placeholder="Username" /><br/>
            Password:<br/><input type="password" name="pwd" placeholder="Password" /><br/>
            Please choose a file: <input name="txt_file" type="file" size="35" />
            <input type="submit" name="start_upload" value="Upload File" onClick="dispProgress()" />
        </form>



    </body>
<html>

Open in new window



I tried using FTP_BINARY and that did not work as well

Thank you for your help in advance
0
Comment
Question by:thomasm1948
  • 2
5 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Where does the failure occur?  We need to know the symptoms of the error -- any messages, etc.  

Check the file sizes - PHP has limits.  The code snippet I posted in your earlier question teaches how to upload files with PHP and shows links to the man page references that you must understand in order to upload files.  I see you're not using those principles yet.  

After you've mastered that part, then you might want to consider integrating the FTP process to send the uploaded files to another server.
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
There is no reason to think that MP4 files are blocked.  It is more likely that your video files are too large and take too long to upload with PHP.
0
 

Author Comment

by:thomasm1948
Comment Utility
I think I figured it out but now I have another issue.  So what I did was change the PHP.ini file for max upload from 2M to 200M then restarted the server thinking everything would be fine.  

Now for some reason my server is not rendering the PHP page.  it only shows code inside.  I am not sure what went wrong.  Even if I change back my settings the end result is the same in that my browser now displays the php code instead of the page

any ideas
0
 

Author Comment

by:thomasm1948
Comment Utility
Figured out the issue.  For some reason I had to uninstall both PHP and HTTPD

yum remove php*

yum remove httpd

and re-install everything by doing this

yum install php*

That also installs httpd.  I then modified the file size for post and upload in the php.ini file.  Now everything works.  I am not sure what happened
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now