Solved

PHP Uploading to FTP server with video files

Posted on 2014-09-24
5
573 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 109

Expert Comment

by:Ray Paseur
ID: 40341799
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 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40341803
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
ID: 40342013
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
ID: 40342248
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

789 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