PDA

View Full Version : loading the contents of a file into a MovieClip via PHP


greygris
12-21-2008, 05:52 AM
I'm trying to load a photo (that has been uploaded with an html form via PHP) from a file path on the server... seems easy, maybe? maybe not for me! here is my php code that I'm trying to get the contents of that file. I'm a beginner in the AS3/PHP thing, any and all advice is much appreciated!!


<?php
$file_path = "files/";
///what the heck do I do here?!
if (!function_exists('file_get_contents')) {
function file_get_contents($filename, $incpath = false, $resource_context = null)
{
if (false === $fh = fopen($filename, 'rb', $incpath)) {
trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
return false;
}

clearstatcache();
if ($fsize = @filesize($filename)) {
$data = fread($fh, $fsize);
} else {
$data = '';
while (!feof($fh)) {
$data .= fread($fh, 8192);
}
}

fclose($fh);
return $data;
}
}
?>

tBeck
12-21-2008, 06:16 AM
I think this should be in the PHP section of this site,...but when you upload a file, it is temporarily stored on the server. You must move the file from $_FILES to a folder on your server. You can move the file that was temporary uploaded using move_uploaded_file provided by php 4.0.3. You can accquire the temporary name with:


$tmpName = $_FILES["inputfield"]["tmp_name"];


inputfield would be the name property of the input tag.

greygris
12-21-2008, 06:56 AM
the jpg file already has been uploaded into a folder via a separate html/php form, but I guess the question here would be, can this script automatically read the contents of the file path (folder) so that I can output it/display in flash? sorry if this kind of confusing... I want to allow the file in that folder to be read dynamically from the name of that exact file. So each time the user uploads a photo into the folder on the server, flash will automatically load the contents of the folder.


thanks!!!

tBeck
12-21-2008, 07:40 AM
So you want flash to get all the files in a folder on your server, correct?

greygris
12-21-2008, 07:59 AM
yes exactly, just one image file... maybe I don't need the php in this case?

well, I'm hoping that I will be able to figure out how to make the other script I have going (that'll be some other situation, when I get to it), replace the file each time the user uploads a new photo using that html form.

tBeck
12-21-2008, 08:35 AM
If your overwriting an image with PHP than there is no point. If you are uploading multiple files and you want to show them all in flash (like a slideshow) then you can use PHP and create a function which will retrieve all the files in the folder, and parse them for flash; so flash knows where the files are and how many there are. If you need help doing this, just let me know.

greygris
12-21-2008, 04:36 PM
hmm, perhaps I should explain the point of this so that I can sort get at goal I'm trying to achieve...btw thanks for being so patient with me!

my client needs a simple admin interface to change out the background photos on their flash site. each swf has one Movieclip which needs a background photo associated with it. I want to make it so that the client can push a button from his admin.html page and the .swf on his site automatically load the photo.

I've been trying for a few days now to getting the AS to retrieve the file from the folder on the server without the exact file name, so that it will just upload whatever is in the folder.. but I can only find it in AS2. I was thinking that maybe I need to push the file name through PHP so that the AS can pick it up?

tBeck
12-21-2008, 09:54 PM
Ok, if theres multiple files in the folder and your trying to find the one that was most recently uploaded by the client, this might be a little more complicated because you need something to base your search off like the filenames. Say you named the files he uploaded:..

1.jpg
2.jpg
3.jpg

This would be the best way because than you would be able to search all the files in the folder with php, and just find the image with the highest value..meaning it was the last one uploaded. Or you can save the picture path to a database or text file on the server and just read it back when you need it for your SWF.

To do one of the following you need to create a PHP file that gets the information and returns it by echoing it. The SWF can than call the URL and get the latest picture path; then all you need to do is load the image. I hope this is on the right track, if so..I would pick one of these methods. Let me know if you need help with it.

greygris
12-22-2008, 01:52 AM
the more I think about this particular part the of the project, I'm thinking that I will tell the client that he needs to just do a simple renaming of the jpg file before he uploads it each time, so the html/php form just overwrites the contents of the file. I have this whole other XML situation... that I will have to figure out when it comes them being able to update their links on their menus, so they will just have to deal with this one!

Thanks so much for responding and I'm sure I'll be back soon.