Page 1 of 1
Flash (AS) PHP Image Upload
Posted: Sun Nov 16, 2008 8:10 am
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
Re: Flash (AS) PHP Image Upload
Posted: Mon Nov 17, 2008 12:45 am
by novice4eva
try changing the "post_max_size" to some greater value in php.ini file, maybe that will help!!
Re: Flash (AS) PHP Image Upload
Posted: Mon Nov 17, 2008 7:28 am
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?
Re: Flash (AS) PHP Image Upload
Posted: Mon Nov 17, 2008 10:19 pm
by novice4eva
max_execution_time should be -1(forever value

) , ummm are you working with $_FILE or $_POST!!
Re: Flash (AS) PHP Image Upload
Posted: Mon Nov 17, 2008 10:30 pm
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
Re: Flash (AS) PHP Image Upload
Posted: Mon Nov 17, 2008 10:33 pm
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.
Re: Flash (AS) PHP Image Upload
Posted: Thu Nov 20, 2008 3:37 am
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
Re: Flash (AS) PHP Image Upload
Posted: Thu Nov 20, 2008 4:09 am
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!!
Re: Flash (AS) PHP Image Upload
Posted: Thu Nov 20, 2008 4:13 am
by novice4eva
sorry about that max execution time thing, you are right..my bad

uploading an image from flash using php more specifically HT
Posted: Wed Aug 04, 2010 10:52 am
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?