Ustag Posted September 15, 2011 Share Posted September 15, 2011 Hi, I have a file uploader made in flash pointing to upload.php to place the file in correct location and add info to the database. My problem is that this do not work: //Set some variables$name = $_SESSION['name'];$time = mysql_real_escape_string(time());$date = mysql_real_escape_string(date('Y-m-d'));$ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);$filename = $_FILES['Filedata']['name'];// Move uploaded fileif( $_FILES['Filedata']['error'] == 0 ){ if(move_uploaded_file($_FILES['Filedata']['tmp_name'], "files/".$name."/".$_FILES['Filedata']['name'])) { echo 'ok'; // Insert data into database $sql="INSERT INTO `files` (`filename`,`key`,`time`,`date`,`loc`,`ip`,`user`) VALUES ('$filename','$key','$time','$date','$name','$ip','$name')"; $result=mysql_query($sql); exit(); }} The $name variable do not work and my file is uploaded in just the files folder and the insert into the database get blank where $name should be. But if I do "echo $name;" I will get the right result. Anybody know what might be wrong?I hoe I gave all info that you need to help me solve this. Thank you! Link to comment Share on other sites More sharing options...
Ingolme Posted September 15, 2011 Share Posted September 15, 2011 You'll have to find out where $_SESSION['name'] is being set and make sure that that script works. Link to comment Share on other sites More sharing options...
Ustag Posted September 15, 2011 Author Share Posted September 15, 2011 but if I type echo $name; before the if statements it does echo my username when I enter upload.php manually so it means that it is just not workin inside the if statement which is strange imo. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 15, 2011 Share Posted September 15, 2011 Are you using session_start on that page? Link to comment Share on other sites More sharing options...
Ustag Posted September 15, 2011 Author Share Posted September 15, 2011 Yepp, the session works. It's not working to use the $name inside the if statement, but works outside. Does it have to do with that im using a flash script as uploader? This is what I am using: http://active.tutsplus.com/tutorials/actionscript/creating-a-reusable-flash-uploader-with-actionscript-3-0-and-php/ Link to comment Share on other sites More sharing options...
Ingolme Posted September 15, 2011 Share Posted September 15, 2011 Probably. I don't think that Flash sends the session cookie. Link to comment Share on other sites More sharing options...
Ustag Posted September 15, 2011 Author Share Posted September 15, 2011 is it really flash that controlls whats in the if statement? $time$date$ip$filename all those works outside and inside the if, only the $name dont... if I put the session in $name, should that not be exactly the same as the other variables? Link to comment Share on other sites More sharing options...
Ingolme Posted September 15, 2011 Share Posted September 15, 2011 No, what happens is that when Flash sends a request, it doesn't send the session cookie like the browser does, so in the entire script, $_SESSION[] is empty. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 15, 2011 Share Posted September 15, 2011 Just to be clear, it's not the case that the variable exists outside of an if statement but not inside. Those are the same scope. PHP doesn't work that way where variables that are defined outside of a structure like an if statement are not defined inside of it (all other things being equal). Link to comment Share on other sites More sharing options...
Ustag Posted September 15, 2011 Author Share Posted September 15, 2011 ok thank you, I will research about how to get my session cookie in my flash script. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.