Flash (AS) PHP Image Upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
iceangel89
Forum Commoner
Posts: 39
Joined: Mon Jul 02, 2007 7:02 pm

Flash (AS) PHP Image Upload

Post by iceangel89 »

what i am trying to do: upload an image (BitmapData) from Flash to (PHP) Web Server

i was thinking of using something like AMFPHP for this. because the current method i used ... what other methods can i use?

in AS:
looping thru the pixels and getting the hex value of the pixel

Code: Select all

  for (var a = 0; a<=w; a++) { //width
        for (var b = 0; b<=h; b++) {    //height
            var tmp = snapshot.getPixel(a, b).toString(16);
            pixels.push(tmp); // push values into the array
        }
    }
then in php, create a PHP image

Code: Select all

  for($x=0; $x<=$width; $x++){ // for every x pixels
        for($y=0; $y<=$height; $y++){   // for every y pixels of x
            $int = hexdec($data[$i++]);
            $color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
            imagesetpixel ( $image , $x , $y , $color );
        }
    }
but the prob is the AS pixels array sent to the server as $_POST['img'] is too big and the server gives

Code: Select all

Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 71 bytes) in .../upload.php on line 10
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Flash (AS) PHP Image Upload

Post by novice4eva »

try changing the "post_max_size" to some greater value in php.ini file, maybe that will help!!
iceangel89
Forum Commoner
Posts: 39
Joined: Mon Jul 02, 2007 7:02 pm

Re: Flash (AS) PHP Image Upload

Post by iceangel89 »

thanks for your reply, but it still doesn't work. i also tried setting the max_execution_time to 0 (supposed to be run forever) and 9999 and i think 64MB for post_max_size shld be more than enough.

i run my script on localhost and save the output from something like $_POST['img'] gives a file of ~2MB only

i tried if i reduce the amt of data sent it works, but fails when the amt of data sent is too big.

i am wondering if i split the data to be sent into different POST vars will it work?
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Flash (AS) PHP Image Upload

Post by novice4eva »

max_execution_time should be -1(forever value :mrgreen: ) , ummm are you working with $_FILE or $_POST!!
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Flash (AS) PHP Image Upload

Post by novice4eva »

I was going through the PHP site, it reads that you should set the "memory_limit" to figure greater than "post_max_size"
http://www.php.net/manual/en/ini.core.php
Tell us if it works
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Flash (AS) PHP Image Upload

Post by Eran »

What is happening on line 10 of upload.php? Is it possibly inside the loop you showed?
Setting every pixel individually seems very inefficient - especially for higher-res images. It could be what's running you out of memory.
iceangel89
Forum Commoner
Posts: 39
Joined: Mon Jul 02, 2007 7:02 pm

Re: Flash (AS) PHP Image Upload

Post by iceangel89 »

pytrin: line 10 is line 2 of the code i gave (yes, inside the loop)

my memory limit is 32MB far more than my max_post_size of 8MB. if my data posted is >8MB i shld get some error? but i dont get any? its just that the POST contains no data... this is strange ...

novice4eva: according to http://sg.php.net/function.set-time-limit the method i used 0 is for no time limit, maybe its different if i used ini_set()

novice4eva: and i am working with POST, the only way i seem to be able to use $_FILES is by FileReference - http://livedocs.adobe.com/flash/8/main/ ... 02204.html but the method provided upload() requires a browse for file, but what i want to to transfer an ActionScript image not an image from the users computer. so i used POST sending all pixels info across, i know obviously thats not anywhere near the best way... but i am running short of time
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Flash (AS) PHP Image Upload

Post by novice4eva »

The error says 33554432 bytes exhausted that is equivalent to umm 32MB so
my memory limit is 32MB far more than my max_post_size of 8MB.
max_post_size must be greater than at least 32 MB i guess, making the mermory_limit to even more!!
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Flash (AS) PHP Image Upload

Post by novice4eva »

sorry about that max execution time thing, you are right..my bad :roll:
indievidual
Forum Newbie
Posts: 1
Joined: Wed Aug 04, 2010 9:54 am

uploading an image from flash using php more specifically HT

Post by indievidual »

I currently have it working so it displays a dialogue box to save the image on your computer:

if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{

// get bytearray
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];

// add headers for download dialog-box
header('Content-Type: image/jpeg');
header("Content-Disposition: attachment; filename=".$_GET['name']);
echo $jpg;
}
just wondered if there is any way to put the file straight into a directory/file without the need of a dialogue box? or just save to server directory at all>?

like an uploader?
Post Reply