• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Upload photo from gallery to database, possible with GM?

S

Simeon3

Guest
Hi,

I am not asking you guys to program anything for me, but I would like
you to help me with leads on how to do this because I am kinda lost?

Are there any tutorials?

Thanks /S
 

Bingdom

Googledom
As in, add sprites from external resources?

sprite_add()
background_add()

Useful if you want to show saved screenshots in your game.
The only thing you need is the directory, name and file type. ;)
 

Tulloch

Member
I would recommend looking into php scripts that allow you to upload files with a restfulAPI through JSON. Then you can use the HTTP functions to upload the image and store them in database for later retrieval.
 

dphsw

Member
May I as novice ask how php is related to GMS? Can I do php in GMS?
Thx
They aren't really related, and no, you can't really do one "in" the other, as such. PHP is a web programming language. (Notice the '.php' in the url of this page, where it says, 'forum.yoyogames.com/index.php', indicated that this forum is written using PHP.) Webpages can be computer programs themselves these days, like this forum, which can take data (like a forum post) and store it a database, and then recall data from that database. The idea being suggested here is that you would use PHP to make a webpage that has the function of taking some data and storing it in a database. Then you could use GameMaker's HTTP functions to request that webpage and send or request data, and your PHP webpage can interpret that request appropriately. So they are separate languages, but they can be made to interact with each other.
 

Tornado

Member
Thanks for your answer. Actually I'm senior Java and web(no designer) developer (but GMS rookie) I just couldn't connect the question and your first answer.
So you proposed that database is behind a web site and GMS reads the image from the gallery and uploads it via HTTP(S) to the website which saves it in the database?
 

dphsw

Member
Thanks for your answer. Actually I'm senior Java and web(no designer) developer (but GMS rookie) I just couldn't connect the question and your first answer.
So you proposed that database is behind a web site and GMS reads the image from the gallery and uploads it via HTTP(S) to the website which saves it in the database?
Basically, yes. GMS has some functions like http_get and http_post_string for making web requests, there's quite a bit of information if you google those. In fact, if you're a web developer, you may prefer to use the http_request function which lets you compose all the http headers and stuff yourself in case there's any custom information you want to include.
There's also the question of how to actually work with the data for a picture. GML isn't generally keen on you doing that, but if you look up the section of the manual on buffers, the buffer_get_surface command and the buffer_base64_encode command will let you convert a picture to a stream of text. It won't be compressed at all, but it's the only way I know of so far to get picture data.

I'm not sure what was meant by 'the gallery' in the first question - given the ensuing conversation, I had the idea it meant uploading a screenshot during the game. If the intention is for a mobile game to access the mobile phone's gallery, I think you'll need an extension for that. If you search the marketplace, I expect you'll find such extensions available, although they might not be free. Being a Java developer, you may be able to make extensions for the Android phone yourself, though I don't have experience of that. Clearly stuff like that is possible - this extension offers access to the camera in gamemaker, for example:
https://marketplace.yoyogames.com/assets/1359/android-camera
 

Tornado

Member
I'm not an original poster and don't (yet) have such requirement I just wanted to understand the answer. You never know when you need such things. For now I'm bloody rookie in this game developing stuff.
Thank you for your time and all clarifications. Hope this all will come handy for OP.
Take care
 

Tulloch

Member
I can probably do a tutorial on this at some point. It seems to be in high demand and I'd love to see more games utilizing the http functions.
For now, I would recommend checking out Zack Banack's stuff on the marketplace. I've learned everything I know about GM:S's online functions thanks to these assets. Not that I'm affiliated with him in any way, but you'll get the most bang for your buck with his "Banack Bundle" which includes more than enough to get you started. Each asset includes a PHP script to upload to your hosting as well. I hope this helps you, it has helped me greatly!
 
Top