jonasvermeulen
%Europe/Berlin %744 %2009, 18:51
hi,
ik heb een script in php die bestanden upload naar de server en vervolgens ook in de database zet welk bestand dat was (bij de gebruiker die heeft geupload).
Als ik het php bestand zonder flash uitvoer dan wordt de sessievariabele wel ingesteld, maar als ik het bestand aanroep vanuit flash wordt de sessievariabele plots niet meer ingesteld, dit komt denk ik omdat ik in mijn flashbestand een browsedialog aanroep.
hoe kan ik dit oplossen?
JOnas
php:
<?php
session_start();
if (isset($_SESSION['user_logged_in'])) {
echo 'set';
$ya = 'set';
}
$todayDate = $_POST['todayDate'];
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$filename = $_FILES['Filedata']['name'];
$filetmpname = $_FILES['Filedata']['tmp_name'];
$fileType = $_FILES["Filedata"]["type"];
$fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000);
mysql_connect("xx.xxxxxxxx.xx", "xx_xxxxxxxxxxx", "xxxxx") or die ("geen connectie naar mysql" . mysql_error());
mysql_select_db("xx_xxxxxxx_xxxxxx") or die ("geen database gevonden" . mysql_error());
$queryupdate = "UPDATE WROX_USER SET AVATAR_LINK='" . $filename . "' WHERE USERNAME='" . $sessieuser . "'";
$resultupdate = mysql_query($queryupdate) or die (mysql_error());
$queryselect = "SELECT AVATAR_LINK FROM WROX_USER WHERE USERNAME='" . $_SESSION['user_logged_in'] . "'";
$resultselect = mysql_query($queryselect) or die (mysql_error());
$resultselect = mysql_fetch_array($resultselect);
if ($resultselect['AVATAR_LINK'] == "") {
echo("no unlink");
}else{
echo("unlink");
unlink("avatars/". $filename);
}
echo ("Er zijn '" . mysql_affected_rows() . "'records bijgewerkt");
echo '<pre>' . print_r (htmlentities ($queryupdate), true) . '</pre>';
// Place file on server, into the images folder
move_uploaded_file($_FILES['Filedata']['tmp_name'], "avatars/".$filename);
// This section edits your log file, if you don't need a text log file just delete these lines
$myFile = "logFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "\n\ntodayDate: $todayDate \n Name: $Name \n Email: $Email \n ssid: $ssid \n FileName: $filename \n TmpName: $filetmpname \n Type: $fileType \n Size: $fileSizeMB MegaBytes \n Errors: '". mysql_error()."' \n affected rows: '". mysql_affected_rows() ."' \n <pre>'" . print_r (htmlentities ($queryupdate), true) . "'</pre> \session set?:'". $sessieuser. "'\n resultselect: '". $resultselect['AVATAR_LINK']. "' \n set? : '". $ya ."'";
fwrite($fh, $stringData);
fclose($fh);
// End log file edit
?>
as3:
/*
Script Written By: Adam Khoury @ www.developphp.com
*/
// First thing is to set the flashing upload message clip to invisible
uploadMsg.visible = false;
// Set the URL for the PHP uploader script
var URLrequest:URLRequest = new URLRequest("http://yourgamerpage.byethost10.com/uploader_script.php");
// Assign the image types Filter
var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
// Assign the document types filter
var textTypes:FileFilter = new FileFilter("Text Files (*.txt, *.rtf)", "*.txt; *.rtf");
// Add both filter types to an array
var allTypes:Array = new Array(imageTypes, textTypes);
// Set the FileReference name
var fileRef:FileReference = new FileReference();
// Add event listeners for its various fileRef functions below
fileRef.addEventListener(Event.SELECT, syncVariables);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
// Add event listeners for your 2 buttons
browse_btn.addEventListener(MouseEvent.CLICK, browseBox);
upload_btn.addEventListener(MouseEvent.CLICK, uploadVars);
// Function that fires off when the user presses "browse for a file"
function browseBox(event:MouseEvent):void {
fileRef.browse(allTypes);
}
// Function that fires off when the user presses the "upload it now" btn
function uploadVars(event:MouseEvent):void {
uploadMsg.visible = true;
fileRef.upload(URLrequest);
upload_btn.visible = false;
}
// Function that fires off when File is selected from PC and Browse dialogue box closes
function syncVariables(event:Event):void {
fileDisplay_txt.text = "" + fileRef.name;
blocker.visible = false;
upload_btn.visible = true;
progressBar.width = 2;
var variables:URLVariables = new URLVariables();
variables.todayDate = new Date();
variables.Name = "Dude"; // This could be an input field variable like in my contact form tutorial : )
variables.Email = "someDude@someEmail.com"; // This one the same
URLrequest.method = URLRequestMethod.POST;
URLrequest.data = variables;
}
// Function that fires off when upload is complete
function completeHandler(event:Event):void {
uploadMsg.visible = false;
blocker.visible = true;
status_txt.text = fileRef.name + " has been uploaded.";
fileDisplay_txt.text = "";
}
// Function that fires off when the upload progress begins
function progressHandler(event:ProgressEvent):void {
// we want our progress bar to be 200 pixels wide when done growing so we use 200*
// Set any width using that number, and the bar will be limited to that when done growing
progressBar.width = Math.ceil(200*(event.bytesLoaded/event.bytesTotal));
}
ik heb een script in php die bestanden upload naar de server en vervolgens ook in de database zet welk bestand dat was (bij de gebruiker die heeft geupload).
Als ik het php bestand zonder flash uitvoer dan wordt de sessievariabele wel ingesteld, maar als ik het bestand aanroep vanuit flash wordt de sessievariabele plots niet meer ingesteld, dit komt denk ik omdat ik in mijn flashbestand een browsedialog aanroep.
hoe kan ik dit oplossen?
JOnas
php:
<?php
session_start();
if (isset($_SESSION['user_logged_in'])) {
echo 'set';
$ya = 'set';
}
$todayDate = $_POST['todayDate'];
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$filename = $_FILES['Filedata']['name'];
$filetmpname = $_FILES['Filedata']['tmp_name'];
$fileType = $_FILES["Filedata"]["type"];
$fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000);
mysql_connect("xx.xxxxxxxx.xx", "xx_xxxxxxxxxxx", "xxxxx") or die ("geen connectie naar mysql" . mysql_error());
mysql_select_db("xx_xxxxxxx_xxxxxx") or die ("geen database gevonden" . mysql_error());
$queryupdate = "UPDATE WROX_USER SET AVATAR_LINK='" . $filename . "' WHERE USERNAME='" . $sessieuser . "'";
$resultupdate = mysql_query($queryupdate) or die (mysql_error());
$queryselect = "SELECT AVATAR_LINK FROM WROX_USER WHERE USERNAME='" . $_SESSION['user_logged_in'] . "'";
$resultselect = mysql_query($queryselect) or die (mysql_error());
$resultselect = mysql_fetch_array($resultselect);
if ($resultselect['AVATAR_LINK'] == "") {
echo("no unlink");
}else{
echo("unlink");
unlink("avatars/". $filename);
}
echo ("Er zijn '" . mysql_affected_rows() . "'records bijgewerkt");
echo '<pre>' . print_r (htmlentities ($queryupdate), true) . '</pre>';
// Place file on server, into the images folder
move_uploaded_file($_FILES['Filedata']['tmp_name'], "avatars/".$filename);
// This section edits your log file, if you don't need a text log file just delete these lines
$myFile = "logFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "\n\ntodayDate: $todayDate \n Name: $Name \n Email: $Email \n ssid: $ssid \n FileName: $filename \n TmpName: $filetmpname \n Type: $fileType \n Size: $fileSizeMB MegaBytes \n Errors: '". mysql_error()."' \n affected rows: '". mysql_affected_rows() ."' \n <pre>'" . print_r (htmlentities ($queryupdate), true) . "'</pre> \session set?:'". $sessieuser. "'\n resultselect: '". $resultselect['AVATAR_LINK']. "' \n set? : '". $ya ."'";
fwrite($fh, $stringData);
fclose($fh);
// End log file edit
?>
as3:
/*
Script Written By: Adam Khoury @ www.developphp.com
*/
// First thing is to set the flashing upload message clip to invisible
uploadMsg.visible = false;
// Set the URL for the PHP uploader script
var URLrequest:URLRequest = new URLRequest("http://yourgamerpage.byethost10.com/uploader_script.php");
// Assign the image types Filter
var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
// Assign the document types filter
var textTypes:FileFilter = new FileFilter("Text Files (*.txt, *.rtf)", "*.txt; *.rtf");
// Add both filter types to an array
var allTypes:Array = new Array(imageTypes, textTypes);
// Set the FileReference name
var fileRef:FileReference = new FileReference();
// Add event listeners for its various fileRef functions below
fileRef.addEventListener(Event.SELECT, syncVariables);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
// Add event listeners for your 2 buttons
browse_btn.addEventListener(MouseEvent.CLICK, browseBox);
upload_btn.addEventListener(MouseEvent.CLICK, uploadVars);
// Function that fires off when the user presses "browse for a file"
function browseBox(event:MouseEvent):void {
fileRef.browse(allTypes);
}
// Function that fires off when the user presses the "upload it now" btn
function uploadVars(event:MouseEvent):void {
uploadMsg.visible = true;
fileRef.upload(URLrequest);
upload_btn.visible = false;
}
// Function that fires off when File is selected from PC and Browse dialogue box closes
function syncVariables(event:Event):void {
fileDisplay_txt.text = "" + fileRef.name;
blocker.visible = false;
upload_btn.visible = true;
progressBar.width = 2;
var variables:URLVariables = new URLVariables();
variables.todayDate = new Date();
variables.Name = "Dude"; // This could be an input field variable like in my contact form tutorial : )
variables.Email = "someDude@someEmail.com"; // This one the same
URLrequest.method = URLRequestMethod.POST;
URLrequest.data = variables;
}
// Function that fires off when upload is complete
function completeHandler(event:Event):void {
uploadMsg.visible = false;
blocker.visible = true;
status_txt.text = fileRef.name + " has been uploaded.";
fileDisplay_txt.text = "";
}
// Function that fires off when the upload progress begins
function progressHandler(event:ProgressEvent):void {
// we want our progress bar to be 200 pixels wide when done growing so we use 200*
// Set any width using that number, and the bar will be limited to that when done growing
progressBar.width = Math.ceil(200*(event.bytesLoaded/event.bytesTotal));
}