Jump to content

Facebook File Upload?


Recommended Posts

Hey guys!I'm making a facebook app for auditions where people can upload a video audition with their name and email to audition.I want it so that there is just one form with name, email and file.How do I do this so I can upload a video to my server and put the name and email in the database with the link to the video?I'm confused :)

Link to post
Share on other sites

well, first thing's first is learning how to make a form with HTML. With that you can submit user input to a server side script that insert the video to directory of your choosing, as well as record the relevant location and user data into a database. Do you know how to make a form and have it submit to a server side script?

Link to post
Share on other sites

Yeah I've created the form in HTML with the 3 fields but in PHP it seems to ignore the file completely and doesn't bother saving it.I just wanted some clarification on how you would do it.

Link to post
Share on other sites

PHP doesn't "ignore" the file. It just doesn't know what exactly to do with it. You need to explicitly specify what you want to do with the given file.What's your current PHP code doing? Show it.

Link to post
Share on other sites

Probably because of XAMPP... how are you moving the file? move_uploaded_file() I'd hope? Make sure you have error display turned on. There might be some errors in your code. If you show us your actual code, we might be able to try it and reproduce the error.

Link to post
Share on other sites

empty() or simply var_dump()'ing everything and inspecting it "manually".Would you please finally share some actual code we could test?

Link to post
Share on other sites

Still confused :)

<?php$page = "audition";$pagename = "Audition";require_once('core.php');if ($_POST['submit']) {	// Process Form then send to Thanks Page	$name = $_POST['name'];	$email = $_POST['email'];	$video = $_POST['video'];	$act_desc = $_POST['act_desc'];		// Check if the user has filled them in!	if (!$name || $name == "") {		// No Name!		$error = "Your name could not be included with the form. (ErrorCode #3)";	}	if (!$email || $email == "" && !$error) {		// No Email!		$error = "Your Email Address could not be included with the form. (ErrorCode #3)";	}	if (!$video || $video == "" && !$error) {		// No Email!		echo $_FILES["file"]["tmp_name"];		$error = "Please attach your video. (ErrorCode #4)";	}	if (!$act_desc || $act_desc == "" && !$error) {		// No Desc!		$error = "Please tell us about your act. (ErrorCode #4)";	}	if (!$error) {		// Form Valid!		// Upload the video and grab link back		if (file_exists("upload/".$_FILES["file"]["name"])) {			$filename = $_FILES["file"]["name"] . "_new";		}		else {			$filename = $_FILES["file"]["name"];		}		$upload_file = move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $filename);		$videolink = "upload/".$filename;				// Debug		if (!$upload_file) {			echo "File Upload / Move failed! (ErrorCode: #13)";		}		else {			echo "File is fine :). (".$videolink.")";		}				// Tell the DB		$query2 = mysql_query("UPDATE users SET auditioned = 1 WHERE uid = '".$uid."'");		if (!$query2) {			$error = "Could not contact database. (ErrorCode #8)";		}		else {			// SENT!			// SEND EMAILS!			$msgtov = "$name has sent a video audition via CUT on Facebook:			Facebook Profile: http://www.facebook.com/profile.php?id=$uid			Name: $name			Email Address: $email			Link to Video: LINK			Description of Act: 			$act_desc			Please do not delete this email! The Database does not hold records for this information!";			$mail1 = mail($config['email'],"Form Submission (Facebook)",$msgtov,"From: Mailer Bot");						// Mail2			$msgtou = "Thanks for sending your video audition for CUT!			If you need any assistance please feel free to email us by replying to this email.			We will contact you soon.			Our FB Page: LINK";			$mail2 = mail($email,"Thanks for Auditioning for CUT!",$msgtou,"From: ".$config['email']);			}		}	}?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd"><html lang="en"><head>	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">	<title><index><?php echo $pagetitle; ?></title>	<meta name="generator" content="TextMate http://macromates.com/">	<meta name="author" content="James King">	<!-- Date: 2011-02-03 --></head><body><div id="fb-root"></div>	<script type="text/javascript"><?phpif ($top_href) {	?>	top.location.href = "<?php echo $top_href; ?>";	<?php} else {	?>	window.fbAsyncInit = function() {	  FB.init({		appId   : <?php echo $facebook->getAppId(); ?>,		session : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it		status  : true, // check login status		cookie  : <?php echo $config['fb']['cookie']; ?>, // enable cookies to allow the server to access the session		xfbml   : true // parse XFBML	  });	  // whenever the user logs in, we refresh the page	  FB.Event.subscribe('auth.login', function() {		window.location.reload();	  });	};	(function() {	  var e = document.createElement('script');	  e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';	  e.async = true;	  document.getElementById('fb-root').appendChild(e);	}());	<?php}?></script><style type="text/css" media="screen">	h1, h2 {		font-family: Verdana;	}	.form {		border: solid 1px gray;		background: silver;		width: 75%;		height: auto;	}</style><center><?phpif ($auditioned == 0) {	?>	<?php		if ($error) {		echo "<font color=\"red\">Error: <b>".$error."</b></font><br /><br />";	}		?>	<h1>Submit your Video for CUT!</h1>	<h6>(All Fields are Required And You must live near CUT to attend)</h6><br />	<div class="form">		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" accept-charset="utf-8" enctype="multipart/form-data">		<br /><input type="hidden" name="uid" value="<?php echo $uid; ?>">		<input type="hidden" name="name" value="<?php echo $me['name']; ?>">		<input type="hidden" name="email" value="<?php echo $me['email']; ?>">		Please Attach your Video: <br /><input type="file" name="video" value=""><br /><br />		Please Explain Your Act:<br /><textarea name="act_desc" rows="12" cols="60"><?php echo $act_desc; ?></textarea><br /><br />		<input type="submit" name="submit" value="Submit Video Audition"><br /><br />	</form></div><br />	<?php}else {	?>	<p>Thanks for Auditioning! Please check your emails for our reply. If you experience any issues please email us at <?php echo $config['email']; ?>.</p>	<?php}?><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like-box href="LINK?v=info" width="292" show_faces="true" stream="false" header="true"></fb:like-box></center></body></html>

Edited by jamesking56
Link to post
Share on other sites

So many undefined variables... how am I supposed to test this? Could you possibly reduce it (it will help you too once you look at how your full code differs from your reduced sample).On first sight, the only problems I can see are1. Your Facebook JavaScript comes after you attempt to use a Facebook object... that probably influeces the whole flow of your app. Move

<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>

somewhere around

<div id="fb-root"></div>	<script type="text/javascript">

or move the JavaScript at that part somewhere after that script call.2. Replace

if ($_POST['submit']) {

with

if (isset($_POST['submit'])) {

3. Replace

<title><index>

with

 <title>

(where on earth did this "index" come in?)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...