Hey,
I need some advice so I'll explain what I'm trying to accomplish, how I think I want to do it and I hope someone can tell me if this a good idea or if I'm over-thinking it.
What I want to do it take a bitmap image from an as3/Flash IDE project and save it on a database server. This is a permanent installation that has 4 flash apps running and they all link to a MySQL database.
I found this tutorial that shows me how to serialize bitmapdata and then store it on the local computer but what I'd instead like to do is store that compressed bitmap data in the database in a blob field. Is this a good idea?
If not can I send it to php to store the bitmapdata into a folder on the server and store a reference to it in the database? I can convert it to jpeg to email from the server at the moment but I need a copy that is still in bitmap format to be picked up by a 5th app and printed out.
If I do store it as a file should I then use PHP to grab the file and stream the bytes back to Flash? Is there a better way of doing it?
Any tutorials or code snippets would be greatly appreciated. If not just a push towards the right subject to read up on.
Thanks guys.
Ben
There has been great debate over the years about whether or not to store images in the DB itself. I think most of that is over and the consensus is rapidly heading to 'store it on the filesystem with a link'... you can scale that up easily, but scaling up a DB is much much harder. All of that's fine by me, because I always thought the DB guys were nuts.
For transfer over the wire, I'd suggest PNGing the image, depending on what kind of image it is (PNG is both compressed and lossless).
How to store the file will depend on how your app is structured. You can probably get by with large folders full of MD5 generated filenames to prevent collision. You probably don't want to store anything serially, as that makes it easy for somebody to come in and just take the entire set. You can also store autogenerated filenames in user id'd folders... that's up to you.
Unless high security is needed, you can just keep them all on a Web server and shoot back a URL, which makes the files readily available. If you need to keep them private, then you can stream them back with PHP. Make sure you use Etags or some other caching mechanism.
Added:
Btw, the PHP/MySql part is actually pretty easy. All in all, a seasoned pro could do it in a couple of days -- week tops.
And here's the AS3 PNG encoder, which is part of AS3CoreLib
i answered a similar question about saving bitmap into jpg file using as3 and php
Save image from Flash, send it to PHP and return a URL string to Flash
Related
I am currently learning the CodeIgniter framework and would like some help with uploading/displaying images.
I am working with a customer table in which there is an 'avatar' field, which, as the name suggests, is a unique image which is reserved for and represents its respective customer.
I ask in this fashion because know that in C# and SQL Server, you can convert an image to "Binary" and save it in the DB; and likewise read the same "Binary" from the database, and convert it into an image.
I am wondering if the above, or something similar, is also possible in PHP...
After some research I see that most people are using the file location of the image, which I do not want to do. What's the point of type "BLOB" if I can simply save the location of the image instead?
If I am mistaken or misunderstanding any concepts please to clarify respectfully, that I may learn.
TLDR;
How do I go about saving/retrieving an image to and from the database without concerning myself with its file location? If this is impossible, then what's the point of "BLOB"?
I am working on WAMP and am using mysqld.
Sincere help is appreciated, thank you all in advance.
Blobs are ways of storing files and file systems in databases. Creating an image Blob will store the file in a container in your database. It is also a convenient way of packaging a number of files into a single database object. Blobs are not very widely used since it is generally simpler to access the file system containing the content directly.
Unsurprisingly most developers don't seem to enjoy the concept of 'filesystems inside of databases'.
A mobile AIR app needs to send a large image to the back end for later display in a web page.
It takes for ever for PNGEncoder in the AIR app to complete, so the idea is to convert the image data to a ByteArray, compress it and send it to the PHP backend where it is saved as PNG by the PHP code. So I'm looking to port PNGEncoder.as and BitmapData class to PHP to accomplish this. I found PNGEncoder.as in as3corelib but can't find source for BitmapData class that it uses.
So the questions are
1. Is there code out there that does what I'm trying to do?
2. Where can I find BitmapData source code?
3. Is there another way to accomplish this that I'm missing?
Note1. I realize that I can decompile airglobal.swf where BitmapData resides, but looking for a cleaner way
Note2. I'm aware of AMFPHP but it does not support BitmapData type
Thanks
Andy
I see two solutions to this issue.
First, you can consider using a Worker to do just the conversion and sending routine, because image conversion is a pretty standalone and straightforward task to offload, and since most modern devices have more than one core anyway, it's better to put the hardware to work on the client rather than on server. Of course, you will have to take some measures to provide the worker instance with required data and to properly upload the image (cookies might not be handled well in a worker), but this approach is generally cleaner and requires no server side alterations.
The second approach is to use BitmapData.getPixels() to convert a region of pixels into a sequence of bytes, then send them unaltered to the server for conversion. Be warned however, the amount of data in a raw bitmap can be too large for the server to accept, you are looking to no less than 4 bytes per pixel, as bitmaps in AS3 are 32-bit. You can use a server side image encoder to convert raw data on the server after uploading.
I am building a site similar to thefuture.fm. DJs are able to upload MP3 files and set if the file only can be streamed or streamed and downloaded.
Visitors to the site don't have to login to listen to music. They should be able to stream/download these MP3 songs depending on the users settings.
I am using the jPlayer to play songs. I have searched all over the web but can't find any solution. Does jPlayer have any facility like prevent downloading of MP3 files? Or is there any way I can prevent this?
It's actually impossible to prevent downloading. You can make it harder for somebody, but he still needs to download all the data to hear the song. So even if you use some encryption to send the data to a flash player you write yourself, the player will have to decrypt it and play the audio. And since you can decompile flash it wouldn't be to hard to find out the algorithm. He could also just record the music again when playing it (similar to the first DVD decrypt tools, who just took a screenshot 30 times/sec to pass million dollar security measurements)
So the goal is to make it harder, not impossible.
Personally I would go for temporary available links in combination with a cookie, so I can still use jplayer and don't have to reinvent the wheel. Also use some obfuscating to make it harder to read the URL.
When somebody request the main URL (where you show your player) generate a unique key and save it in a cookie. The unique key should link to the IP address and request time stored in session.
Now create a link to the music file like playfile.php?file=music.mp3 or whatever. Just make sure that PHP will handle the file request. If you obfuscate this link it will be a little harder to find it.
In playfile.php check for the unique code in the cookie and check if it matches the IP address in session and the request time is less then EG 15 seconds (any longer and music won't play anyway with slow internet connection). If it is, stream the file. If it's not, block it.
Now if somebody would write a program/script to download the music, he can. But if somebody has the knowledge and time to do that, nothing will stop him from downloading it.
This will prevent any normal user from downloading it.
Preventing hotlinking is a bit easier, since in general you'll have a referrer string to check. If this is present then you'll know not to serve the content. Here is a code example.
Preventing downloading on the other hand is much harder - the best approach would be for a Flash application to decrypt data in realtime - if you use a simple encryption scheme, most client hardware should be fast enough. I couldn't find much for this on the web, so I wonder whether you'd have to do some Flash/Flex development yourself: download MP3 data in chunks, apply decryption routines from a library, and send them to some sort of MP3 decoding buffer. I suspect the password would be hard-coded.
Addendum: I've found that in later versions of Flash you can play dynamically generated sounds from a buffer (see here). So, if you're willing to get stuck into some Flash/Flex development, a solution is in sight. I couldn't find anything that accesses low-level MP3 routines, but don't forget that files don't have to be MP3 as transmitted from your server - convert them to whatever your app needs.
What you are searching for can't be achieved with JavaScript solution. If you want javascript to play something, it has to download it and in order to download it, JavaScript needs a URL.
Most common way to tackle this problem is using Adobe Flash and making a player in it. You can make your player stream content (mp3 in your case) without explicitly exposing actual data location to user.
Put the file(s) in a location that isn't accessible from the browser and use PHP to stream them out as a series of chunks using HTTP/1.1 206 Partial Content. Then use a method like this to edit the context menu to add/remove the 'save as'.
Use a session var to eliminate direct linking.
Actually, there is a player that DOES scramble the url and it works pretty good. We used it because of this excellent feature. It is not impossible to download/save the audio, but at least it is not a matter of just opening the inspector and copying the url. It also prevents from sharing to outside sources by URL. So, contrary to the above, it IS possible and it IS available :)
Check the plugin out here:
https://wordpress.org/plugins/mp3-jplayer/
Well,I am learning the web development and currently working on PHP and mySQL,I am just totally a newbee to database concepts.To be honest Iam not sure when to create a table or when to create a database.I need some suggestions and help from you.
Okay I have these doubt kindly clear me this.I am not much aware of this but how much security does php file concepts provide us. Is there any harm in using file concepts of php?
Okay let me tell you these I want to save some data that user has entered into a text file on the server, the data might be like some message or something like his information,I wanted to save the data in a file and then save its directory path in the database. and while retrieving the data just get the file path from the database then retrieve it from the text file. Is this a good or bad idea of doing it? or should I need to save the user data in the database itself?
Similarly I also want to save the path of the images or pictures in the database and then just put the path in <img>tag.I got no one here to help me with this questions.So please help me with this,Any help is greatly appreciated.
Kindly let me know what is the way I should choose to do ?
For images and other file-bound resources, it makes sense to store the image on the file system and the path to it in the database. After all, file systems are great for storing files. You can store the file as a binary field in the database, so that's certainly an option. There are pros and cons either way. Personally, I prefer to keep the files on the file system.
I'm not sure where you're going with this:
the data might be like some message or something like his information,I wanted to save the data in a file and then save its directory path in the database
Is there a particular reason why this data needs to be in a file? Or are you just not sure how to store it in a database? If the data is structured and consistently organized then I can't imagine a reason not to keep it in a relational database. (And even if it isn't as structured, I'd probably still look into a database over the file system for this sort of thing.)
Images and other non-relational resources are generally file-bound, so keep them in files. But if you're just storing text in a text file for no other reason than that's what you've always done, I'd recommend using a database.
PHP provides only as much security as the underlying filesystem. But putting files on disk and saving the path in the db is the traditional method.
Files in a database are generally not the best solution. But that's mostly because people talk about storing binaries (e.g. images, zip files, etc...) which would be an opaque blob as far as the database is concerned.
With text files, especially small ones, it'd still be at least somewhat useable by the DB, even if only via SUBSTR() type matching/searching, so this is one case where storing in the DB could make sense.
There is a good rule-of-thumb here:
If it is something, the DB "understands" (such as text), store it in
the DB - you might later want fulltext indexing, search, text transformation, whatever.
If not (e.g. Images), store it in files
as all rules of thumb, this might or might not fit your index finger
I am building a Flash AS3 application that allows users to modify images, and then submit-save them to a server.
The user will then have the ability to log in and access these saved images in a thumbnail gallery. They can either delete an image or click a thumbnail to view it at original size.
I am comfortable with the front end having built something similar in AS2 and Flash 8 a few years back.
What will be required for the backend?
I assume some type of PHP-MySQL database is needed. Not sure about hosting issues requirements as the AS2 application I built never sent any actual binary data, but rather data describing the image transformations. I assume I will need to make use of byteArray?
Is there an existing tutorial or code sample that does something similar available for viewing-download?
Are there any security restriction 'gotchas' associated with FP9 -10 I need to be aware of?
the most simple way is to create the image in the client ... get a BitmapData snapshot of the image using BitmapData::draw ... convert this to JPEG or PNG using the as3corelib, that offers encoders for both formats ... and then just send the raw binary data to the server (store it into the data property of your URLRequest) and there, store it to the file system (retrieve it in $HTTP_RAW_POST_DATA) ... so the whole storage process is just a couple of lines ...
you will need a database of course, for session management (you could rely on PHPSESSION only, but personally i don't trust it), login, registration and to store which image belongs to which user ...
so yeah, the whole netcode/backend/storage thing etc. will be quite a piece of cake (btw. you might wanna look into amfphp) ... designing a good interface and implementing the galery view etc. will be the biggest chunk i guess ...
there are no real security gotchas, as long as your SWF comes from the same server, that it communicates to ...
so good luck then ... ;)
greetz
back2dos
If you are on a shared host, php and mysql are probably already available to you, that is a good way to get started.
In terms of flash communicating with the server, you will have to find a way to turn your pictures into a stream of bytes (byteArray sure), and then use flash's send() to post them to the server. Sending XML Out From Flash
Using php you can receive the images and save them to the db, and show them (turn the stream of bytes back into an image with gd -- gd docs)
Also: you may not ever have to send a stream of bytes if you can find a way to have flash describe the transformations, and have gd repeat them, just a thought.
Are there any security restriction 'gotchas' associated with FP9 -10 I need to be aware of?
Maybe, if you are posting data to a different server, you have to enable it with some xml Send data from Flash to PHP on a different server