Solved

PHP Uploading to FTP server with video files

Posted on 2014-09-24
5
607 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 110

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

737 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