Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JoelAtMoodkie · Feb 18, 2011 at 08:48 PM · phpuploadsqlbinaryblob

Uploading custom filetype to MySQL database

Hiya all,

I've made a custom save file using a BinaryWriter and its various Write() methods. I now want to upload this to a MySQL database as a blob/mediumblob using a WWWForm.

I know how to upload files to a database via Unity, but how would I upload a file like this without its binary data changing when I download it again?

This is my theory ... do you think this would work?

1) Download the local file and use Convert.ToBase64String to convert bytes to string.

//Some code omitted
WWW download = new WWW(localfile);
string fileAsString  = System.Convert.ToBase64String(download.bytes);

2) Send this string to a PHP script on my server using a WWWForm.

WWWForm form = new WWWForm();
form.AddField("filedata", fileAsString);
WWW w = new WWW("http://www.mysite.com/script.php", form);

3) In the PHP script I'll insert the string into my database as a mediumblob with no encoding.

$filedata = $_POST["filedata"];
$query = "INSERT INTO myTable (file) VALUES ('$filedata');";
$sqlResult = @mysql_query($query) or die("Could not connect to database");

Will any of this change the underlying binary data?

Regards, Joel.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JoelAtMoodkie · Feb 18, 2011 at 09:20 PM 0
Share

Just a quick update. Converting using ToBase64String() and back again using FromBase64String() doesn't harm the binary data, so I'm more worried about when swapping data with the database.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JoelAtMoodkie · Feb 18, 2011 at 10:09 PM

I've managed to answer my own question. I've managed to implement my theory above and it all works exactly how it should.

Thanks anyway everyone.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tomazsaraiva · Jun 04, 2012 at 03:47 PM 0
Share

Hey,

How are you selecting the local file? Are you using a standalone or web player application?

Thanks

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

seperate binary retrieved from sql server 1 Answer

PHP high score variable help? 1 Answer

Issue with multiple users uploading own texture to the game 1 Answer

no valid crossdomain policy available 1 Answer

Help with saving XML files with PHP to a server 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges