...

View Full Version : Form field to Upload a specific file, does not upload



wuzhannanan
07-10-2012, 06:18 PM
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:



<?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.

Keleth
07-10-2012, 06:22 PM
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.

wuzhannanan
07-10-2012, 06:27 PM
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.

Arcticwarrio
07-10-2012, 06:36 PM
i would echo $_FILES['video']['type'] and see what it says

Keleth
07-10-2012, 06:38 PM
...

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.

Arcticwarrio
07-10-2012, 06:41 PM
ah yes my bad :)

wuzhannanan
07-10-2012, 06:49 PM
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.

wuzhannanan
07-10-2012, 06:55 PM
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

Keleth
07-10-2012, 07:06 PM
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.

wuzhannanan
07-10-2012, 07:59 PM
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?

wuzhannanan
07-10-2012, 08:02 PM
Nm, I see it, it's in a different directory. Thank you to Keleth and Arcticwarrio for your help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum