PDA

View Full Version : Help sending variables to php using upload



rondog
March 20th, 2008, 06:33 PM
I'm creating an upload app where you select several FLVs, fill in some general information about them and upload them.

The videos are uploading fine. My problem is transferring over the data that they filled out to the upload script to insert into the database.

Here is my function that starts the upload.


function startUpload(e:Event):void {
var params:URLVariables = new URLVariables();
//location variables to be sent
params.cid = cid;
params.sid = sid;
params.tid = tid;
//data variables to be sent
params.title = title;
params.description = description;
params.segtitle = segtitle;
params.location = location;
params.date = date;
params.rights = rights;
params.keywords = keywords;
var request:URLRequest = new URLRequest("upload.php");
request.method = URLRequestMethod.POST;
request.data = params;
var list:Number = filelist.length;
var uploadWhat = fileAr[currentIndex];
try {
uploadWhat.upload(request);
uploadWhat.addEventListener(ProgressEvent.PROGRESS , progressHandler);
uploadWhat.addEventListener(Event.COMPLETE, completeHandler);
status.text = "Uploading " + (currentIndex + 1) + " of " + list;
} catch (error:Error) {
status.text = "Unable to upload";
}
}


and my php:



<?php
include 'connect.php';
//location vars
$cid = $_POST['cid'];
$sid = $_POST['sid'];
$tid = $_POST['tid'];
//data vars
$title = $_POST['title'];
$description = $_POST['description'];
$segtitle = $_POST['segtitle'];
$location = $_POST['location'];
$date = $_POST['date'];
$rights = $_POST['right'];
$keywords = $_POST['keywords'];

/************************************************** *
* upload file.
************************************************** */
$addTime = mktime();
$l_sFileName = strtolower( str_replace( " ", "_", basename( $_FILES['Filedata']['name'] ) ) );
$l_sFilePath = "videos/".$addTime.$l_sFileName;
move_uploaded_file( $_FILES['Filedata']['tmp_name'], $l_sFilePath );

$sql = mysql_query("INSERT INTO video (tape_id,filename,name,thumbnail,description,seg_t itle,location,date,rights,keywords) VALUES ('$tid','$l_sFilePath','$title','','$description', '$segtitle','$location','$date','$rights','$keywor ds'");
?>


I have a feeling its not like AS2, where you would just do

data.title = titlefield.text

and then sendAndLoad..thats the way I know how to do it in AS2, but this being AS3, I'm sure im in the wrong on this one.

Any ideas?

dail
March 20th, 2008, 10:28 PM
Whats the extra ' ' between your $title and $description in the values segment of your mysql_query?

rondog
March 21st, 2008, 01:53 AM
Just an empty string..it was thumbnail, I removed it though because I am now using ffmpeg to create a thumbnail rather than upload an flv and a thumbnail. I actually got the whole thing working. The way I did was correct, i just had a missing paren on my sql statement which is why it wasnt working. Everything is good now tho.

dail
March 21st, 2008, 03:59 PM
Ahh,

I thought it may have been a typo. I'm building pretty much the same app but for images, using php and mysql. Now that I've started to use mysql in Flash, I can't believe I never did before.

android
March 21st, 2008, 07:08 PM
Can php accept a query string when uploading? As if it were this line:

var request:URLRequest = new URLRequest("upload.php?movie_id=something&user=something");

dail
March 21st, 2008, 07:33 PM
Yes it can. Just make sure you use the URLVariables approach to send them to PHP as part of your URL request, var params:URLVariables = new URLVariables();. As is demoed in the code in this thread.

android
March 21st, 2008, 08:26 PM
Ok, but then they are not really sent as a query string?
(by query string I mean: something.php?a=b&c=d ) The stuff that follows the url with "?" and "&".

I never used URLVariables before :) But thanks for the info!