samedi 26 juillet 2014

MySQL - déterminer le nom de la variable de l'id de fichier binaire - requête POST avec PHP - Stack Overflow


This started as a simple question and now has become more of a personal challenge than a question. Here goes!


Background


I have a mobile application that collects user-specified data via standard tables and also collects a single photo that is stored as a binary file. The app allows you to specify the location of a server-side script to handle the data that it collects - the script for the binary object is a different script than the one for the alphanumeric data (app requires them as separate, not me). The documentation/support on the app is sparse (part of the reason this has become a personal challenge more than a question). I am using PHP to handle the data and put it into a MySQL database.


Simple Part: The alpha-numeric data


There are some fields that are pre-defined in the application, such as lat/long. I used serialize($_POST) to insert the results into a temp MySQL database to get the database-specific names so that my PHP code could put them into a MySQL database permanently. For instance, latitude was submitted as ecLatitude - who would have guessed. Once I knew it was ecLatitude I could handle it and put it how/where I wanted. Of course fields I defined were no problem.


Hard Part: The binary object


So now my problem is the binary object (the photo). As with some database fields, I do not have control over the name of the file. Seems that standard practice is to call the file 'file', or if I was using an HTML interface I would call it whatever I wanted, because I could use $_FILES and look for the name I specify. So it seems I need to somehow serialize the binary object to determine the id of the actual file, not the file name. By that I mean that if the file was called picture.jpg and was submitted as photo, I need to know 'photo' not 'picture.jpg'.


Where I'm at


Every example I've seen starts with knowing the name of the binary object id (in this case 'photo'), as you would expect this to be a rather obvious variable. I tried encoding the object prior to serializing it, but that still seemed to return the non-unique name (picture.jpg), not the id, in the MySQL database.


***edit - I tried the following code for the blob-specific script.


$outputfields= serialize(base64_encode($_POST));
$query="INSERT INTO varnames (data) values ('".$outputfields."')";

Is this possible inside PHP, or do I need to do network monitoring?


Sorry if I'm not using the correct terminology - I tried to couch that with my simplistic example terms.



This started as a simple question and now has become more of a personal challenge than a question. Here goes!


Background


I have a mobile application that collects user-specified data via standard tables and also collects a single photo that is stored as a binary file. The app allows you to specify the location of a server-side script to handle the data that it collects - the script for the binary object is a different script than the one for the alphanumeric data (app requires them as separate, not me). The documentation/support on the app is sparse (part of the reason this has become a personal challenge more than a question). I am using PHP to handle the data and put it into a MySQL database.


Simple Part: The alpha-numeric data


There are some fields that are pre-defined in the application, such as lat/long. I used serialize($_POST) to insert the results into a temp MySQL database to get the database-specific names so that my PHP code could put them into a MySQL database permanently. For instance, latitude was submitted as ecLatitude - who would have guessed. Once I knew it was ecLatitude I could handle it and put it how/where I wanted. Of course fields I defined were no problem.


Hard Part: The binary object


So now my problem is the binary object (the photo). As with some database fields, I do not have control over the name of the file. Seems that standard practice is to call the file 'file', or if I was using an HTML interface I would call it whatever I wanted, because I could use $_FILES and look for the name I specify. So it seems I need to somehow serialize the binary object to determine the id of the actual file, not the file name. By that I mean that if the file was called picture.jpg and was submitted as photo, I need to know 'photo' not 'picture.jpg'.


Where I'm at


Every example I've seen starts with knowing the name of the binary object id (in this case 'photo'), as you would expect this to be a rather obvious variable. I tried encoding the object prior to serializing it, but that still seemed to return the non-unique name (picture.jpg), not the id, in the MySQL database.


***edit - I tried the following code for the blob-specific script.


$outputfields= serialize(base64_encode($_POST));
$query="INSERT INTO varnames (data) values ('".$outputfields."')";

Is this possible inside PHP, or do I need to do network monitoring?


Sorry if I'm not using the correct terminology - I tried to couch that with my simplistic example terms.


0 commentaires:

Enregistrer un commentaire