Solved

PHP Uploading to FTP server with video files

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
while read ID; do 4 54
Hta File displays dynamic File names 4 44
Do not understand error message 3 19
how to use jquery variable in mysql query 20 34
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

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