# Flash-\>php-\>mysql and back again

**URL:** <https://forum.kirupa.com/t/flash-php-mysql-and-back-again/216223>\
**Category:** Uncategorized\
**Created:** [February 14, 2007, 5:06pm UTC](https://forum.kirupa.com/t/flash-php-mysql-and-back-again/216223 "2007-02-14T17:06:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shax](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@shax](https://forum.kirupa.com/u/shax)\
**Post date:** [February 14, 2007, 5:06pm UTC](https://forum.kirupa.com/t/flash-php-mysql-and-back-again/216223/1 "2007-02-14T17:06:12Z")

</div>

Hi, does anyone know the script for a php script backend to a flash app that would upload files? basically i want to upload the file into a mysql database and then using mysql\_insert\_id(); send back the id. I was thinkin of using sessions to store the id and then using loadvars in flash call another php script that would send the id stored in the session. I tried something but it doesn’t seem to update the session variable but does insert into the databse.

\<?  
session\_start();  
require\_once(“database\_connect.php”);  
if ($\_FILES[‘Filedata’][‘name’]){  
$fileName = $\_FILES[‘Filedata’][‘name’];  
$tmpName = $\_FILES[‘Filedata’][‘tmp\_name’];  
$fileSize = $\_FILES[‘Filedata’][‘size’];

```
    $fp = fopen($tmpName, 'r');
    $content = fread($fp, $fileSize);
    $content = addslashes($content);
    fclose($fp);
   
    $query = "INSERT INTO files (file_name, size, file) ".
             "VALUES ('$fileName', '$fileSize','$content')";

    mysql_query($query) or die('Error, query failed');                    
    $_SESSION['fileId'] = "check";

```

}  
?\>
