Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    54
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Form field to Upload a specific file, does not upload

    I have a form that has four fields, and the last field is an upload-file field. I want the user to upload a video file, which must be in one of four formats. The uploaded video will be placed in a folder on my server. Once the form submits, an email is sent to me and the form fields are stored in a database.

    I am getting emails and seeing the information in my database, but I cannot get the upload onto my server. Also, file types that I want to accept are being told that it's not acceptable. For instance, I tried to upload a .mov file and got the message: The file is not a video format we accept.

    I have been talking to some colleagues of mine but I cannot get this fixed. Can someone take a look at this code and offer any advice? Here is my code:

    Code:
    <?php  
     //ftp acess
     $host = "ftp.hostname.com";
     $usr = "username";
     $password = "pass";
     
     //This is the directory where images will be saved 
     $local_file = $_FILES['video']['tmp_name']; 
     $ftp_path = "/upload/".$_FILES['video']['name']; 
    $type = $_FILES['video']['type'];
    $size = $_FILES['video']['size'];
    if($size < 151000000) {
    if(($type == 'video/mpeg') || ($type =='video/mov') || ($type =='video/mp4') || ($type =='video/mpg') || ($type =='video/avi')) {
     //connect to the FTP server
     $conn = ftp_ssl_connect($host, 21) or die("Can't connect to the host!");
    
     ftp_login($conn, $usr, $password) or die("Cannot login");
     
      $upload = ftp_put($conn, $ftp_path, $local_file, FTP_ASCII);
     // check upload status:
    } else {
    	echo "The file is not a video format we accept";
    }
    } else {
    	echo "The size of the file is to large";
    }
    // close the FTP stream
    ftp_close($conn);
    
     //This gets all the other information from the form 
     $name=$_POST['name']; 
     $email=$_POST['email']; 
     $phone=$_POST['phone']; 
     $vid=addslashes(basename($_FILES['video']['name'])); 
     
     // Connects to your Database 
     mysql_connect("localhost", "username", "pass") or die("Error connect: ".mysql_error()) ; 
     mysql_select_db("database_name") or die("Can't connect to Database".mysql_error()) ; 
    
     //Writes the information to the database 
     $query = "INSERT INTO video (videoid, Name, Email, Phone, Video) VALUES ('','$name', '$email', '$phone', '$vid')";
     if(!mysql_query($query)){
    	 echo "Error uploading information";
     }else {
    	 $headers = 'From: '.$email. "\r\n" . 'Reply-To: '.$email. "\r\n". 'X-Mailer: PHO/' . phpversion();
    	 $message = "Name: ".$name . "\r\n";
    	 $message .= "Email : ".$email . "\r\n";
    	 $message .= "Phone number: ".$phone. "\r\n";;
    	 $message .= "Video file: ". $vid;
    	 mail("myemail@gmail.com", "Video uploaded", $message,$headers);
    	header('Location: http://mysite.com/submit/thank-you.php') ;
     }
    
     ?>
    Thank you in advance for any help you can provide.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Comment out the header and processing code in there, and after if($size < 151000000) { add echo $type; and tell us what you get for a file you think should work.

    If the issue you're having is that a variable isn't passing an if statement like you think it should, echo the variable, echo the various components of the if, see if it gives expected results or not. Just now, I had a rather complex math issue with PHP, and I found I was accidentally doubling the value, causing my last if to fail... figured it out by echoing out each step and seeing where it suddenly exploded.

  • #3
    New Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    54
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Ok, I did that and I still get the same message on the next page: The file is not a video format we accept

    But, I do get an email and I do see the fields in my database.

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    i would echo $_FILES['video']['type'] and see what it says

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    ...

    I mentioned, comment out the processing code and the header (the redirect), so you can see what the VALUE of the variable is... we already know its not working, echoing a variable isn't going to change that. You want to know what the variable is after assignment so you can see what's wrong. That was the point of the little story I gave.

    EDIT: Arcticwarrio, since $_FILES['video']['type'] is stored into $type, seeing $type should work fine, but wazhannanan didn't remove the redirect.

  • Users who have thanked Keleth for this post:

    wuzhannanan (07-10-2012)

  • #6
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    ah yes my bad

  • #7
    New Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    54
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Keleth, I'm sorry, I did not understand what you meant by the header and processing code. I don't know which is which; I've very new to PHP and literally got this far by reading tutorials online. I think I've done well so far but some of the terms confuse me.

  • #8
    New Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    54
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Ok, I think I commented out everything correctly. When I submitted an acceptable file, I got this message:

    type = video/quicktimeThe file is not a video format we accept

  • #9
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    And there you go. If the type is being recognized as video/quicktime, then of course it will fail, as you don't accept video/quicktime as a valid type.

  • #10
    New Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    54
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Awesome, now the video is accepted and I am directed to the Thank You page. The last remaining problem is that the video does not upload to my server. It's supposed to be in my /uploads/ folder, but it doesn't go there. Is there any way to determine why this is not working, using a similar echo method?

  • #11
    New Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    54
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Nm, I see it, it's in a different directory. Thank you to Keleth and Arcticwarrio for your help!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •