?
Solved

PHP Uploading to FTP server with video files

Posted on 2014-09-24
5
Medium Priority
?
674 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 111

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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

752 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