# Jpeg preloader form php \[flash mx\]

**URL:** <https://forum.kirupa.com/t/jpeg-preloader-form-php-flash-mx/34263>\
**Category:** Uncategorized\
**Created:** [October 30, 2003, 3:21pm UTC](https://forum.kirupa.com/t/jpeg-preloader-form-php-flash-mx/34263 "2003-10-30T15:21:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vagari](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/vagari/32/216_2.png) [@vagari](https://forum.kirupa.com/u/vagari)\
**Post date:** [October 30, 2003, 3:21pm UTC](https://forum.kirupa.com/t/jpeg-preloader-form-php-flash-mx/34263/1 "2003-10-30T15:21:32Z")

</div>

Hello everyone,  
I tried to do a search but I couldn’t find anything that addressed this.

I am using a premade gallery app… [ImageVue Demo](http://www.imagevuex.com/sites/newx/)

My client does not want images to show up bigger than the movie clip, thus needing to scroll. So I modified the code in PHP and changed the loadmovie action to imitate the thumbnail loader. Only now the loading progress is dead. Everything loads fine, just the loader dies.

I can’t remember the link but I read something about a problem loading dynamic xml into a movie so I tried that solution, buffering the output. Same result. If I just change the loadmovie back and remove the php file everything works fine, is there a solution to this?

Oh yeah, if I load the image just by typing in the url, it works fine, like this, only not the thumb… [direct image](http://www.imagevuex.com/sites/newx/getfile.php?img=content/misc/various%20nice/0004728.jpg)

Code follows…

load call…  
[AS]loadMovie((“getfile.php?img=”+\_parent.prepath+\_parent.file + “&size=default”), \_parent.mytarget);[/AS]

loader code (kinda long, I’m not sure if I should strip anything out)…  
[AS]onClipEvent (enterFrame) {  
myload = \_parent.mytarget.getBytesLoaded();  
mytotal = \_parent.mytarget.getBytesTotal();  
mypercent = Math.round((myload/mytotal)\*100);  
bar.\_xscale = mypercent;  
percent = mypercent+" %";  
if ((myload == mytotal) and (myload\>1000) and (\_parent.mytarget.\_width\>0)) {  
\_parent.firstimagesuccess=1;  
//new write filename  
\_parent.nutopText = "image “+(\_parent.image+1)+” - "+\_parent.file;  
\_parent.testhead.text = \_parent.nutopText;  
\_parent.testlength = \_parent.testhead.textWidth;  
//  
\_parent.thumbnailtoggler.\_visible = 1;  
if (\_parent.mytarget.\_width\<=640) {  
\_parent.wsmall = 1;  
\_parent.mytarget.\_x = -(\_parent.mytarget.\_width-640)/2+31;  
} else {  
\_parent.mytarget.\_x = 31;  
\_parent.wsmall = 0;  
}  
if (\_parent.mytarget.\_height\<=360) {  
\_parent.hsmall = 1;  
\_parent.mytarget.\_y = -(\_parent.mytarget.\_height-360)/2+39;  
} else {  
\_parent.mytarget.\_y = 39;  
\_parent.hsmall = 0;  
}  
\_parent.tsmall = \_parent.hsmall+\_parent.wsmall;  
\_parent.desc = \_parent.\_parent.image.firstChild.childNodes[\_parent.image].firstChild.nodeValue;  
\_parent.thumbfield = \_parent.\_parent.\_parent.thumbnailofftext;  
\_parent.cachearray[\_parent.image]=1;  
\_parent.thumbindex = 0;  
\_parent.filedisplay = \_parent.file.toUpperCase();  
\_parent.display = “image “+(\_parent.image+1)+”/”+\_parent.\_parent.imagearray.length;  
\_parent.multibuttons.multi[“clip”+\_parent.image].\_alpha = 50;  
\_parent.cover.transout();  
\_parent.gotoAndStop(\_parent.\_currentframe+1);  
}  
}[/AS]

and the php file…

```php
$img=$_GET['img'];
if (isset($_GET['size'])) { $size=$_GET['size']; }
$path = substr($img, 0, strrpos($img, '/'));
$file = substr($img, strrpos($img, '/') + 1);

$tnpath = $path . '/tn_' . $file;
$defPath = $path . '/def_' . $file;

if (@file_exists($defPath)) {
	    Header("Content-type: image/jpeg");
	    readfile($defPath);
	} elseif (!file_exists($img)) {
	    die("Image doesn't exist");
	} else {
	    if (function_exists("imagecreatefromjpeg") and function_exists("imagecreatetruecolor")) {
	        $orig_image = imagecreatefromjpeg($img);
	        $orig_x = imagesx($orig_image);
	        $orig_y = imagesy($orig_image);
			if ($orig_y > 344) {
				$x = round($orig_x / ($orig_y / 344));
	            $y = 344;
				$def_image = imagecreatetruecolor($x, $y);
		        Imagecopyresampled($def_image, $orig_image, 0, 0, 0, 0, $x, $y, $orig_x, $orig_y);	        
				Header("Content-type: image/jpeg");
		        imageJPEG($def_image, '', 100);
				@imageJPEG($def_image, $defPath, 100);
		        imagedestroy ($def_image);
		        imagedestroy ($orig_image);
			} else {
				Header("Content-type: image/jpeg");
			    readfile($path . '/' . $file);
			}
	    } else {
	        header("Content-type: image/jpeg");
	        readfile ('thumb.jpg');
	    } 
	}

```

The big problem with testing is, since it’s using a web server, and the AS isn’t written for it, trying to test the movie just doesn’t load the images and menu cause it can’t do the php calls.

I really need help with this one, please… 🙂 thanks.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 30, 2003, 4:11pm UTC](https://forum.kirupa.com/t/jpeg-preloader-form-php-flash-mx/34263/2 "2003-10-30T16:11:19Z")

</div>

Just a quick update before I go tackle something else for a while…

I set up a dummy text box just to pass the getBytesLoaded, etc. to. IT came back as non-existent basically. I guess this is exactly what I need to fix…

getbytesloaded - getsbytestotal = percent  
0 - -1 = 0%  
0 - -1 = 0%  
0 - -1 = 0%  
0 - -1 = 0%  
0 - -1 = 0%  
0 - -1 = 0%  
16331 - 0 = Infinity%  
48158 - 0 = Infinity%  
48158 - 48158 = 100%

I hope someone knows how to fix this… 🙂 thanks again

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 31, 2003, 5:35pm UTC](https://forum.kirupa.com/t/jpeg-preloader-form-php-flash-mx/34263/3 "2003-10-31T17:35:14Z")

</div>

install a local server ( [www.easyphp.net](http://www.easyphp.net) ) so you can test your php,  
post in the server-side forum for these questions,  
do you still want me/someone to look at this or not…?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 31, 2003, 6:53pm UTC](https://forum.kirupa.com/t/jpeg-preloader-form-php-flash-mx/34263/4 "2003-10-31T18:53:25Z")

</div>

Thanks eyezberg,  
Actually, I already have PHP, plus a bunch of other stuff installed, the problem was that the code I’m using (not originally mine) wasn’t written for this type of thing. I could modify it to perform things correctly, (pretty easily obviously) but as I stated above, I opted to just have it spit out info into a text box on the actual web page.

That aside, it’s irrelevent. I tweaked the getfile.php page and went over it to figure out why it was giving me errors/not caching correctly. I found I needed to place the header command in a different place. Down at the bottom. Everything works perfectly now.

I figured it out through the help of the [Funciton blog](http://www.onelx.com/blog/en/archives/000186.php). They used a similar thing for XML, and I just screwed up in coding the PHP. I wasn’t sure this was a server side problem when I first posted it.

Hopefully it’ll help others, since I couldn’t find any info on it around here.

Here’s the very bottom section of the updated PHP code…

```php

	        header("Content-type: image/jpeg");
	        imageJPEG($sm_image, '', 95);
			@imageJPEG($sm_image, $tnpath, 95);
	        imagedestroy ($sm_image);
	        imagedestroy ($orig_image);
	    } else {
	        header("Content-type: image/jpeg");
	        readfile ('thumb.jpg');
	    } 
	}
}
$buffersize = ob_get_length();
header("Content-Length: $buffersize");
ob_end_flush();
?>

```

Just don’t forget the ob\_start(); code at the top of the page…

Thanks everyone. :nerd:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 1, 2003, 6:06pm UTC](https://forum.kirupa.com/t/jpeg-preloader-form-php-flash-mx/34263/5 "2003-11-01T18:06:22Z")

</div>

thanks for updating, and posting the fix, I hate it when people don’t do that.
