Jump to content

[SOLVED] Run Code Only Once After Array Completes


dlebowski

Recommended Posts

How  would I go about running a portion of my code ONLY after an array completes?  For example, I have a bulk image loader that calls my .php script about 300 times in 7 minutes to upload files to server.  Once those files are copied up, I have another script that creates thumbnails from those images in that directory and copies them into another directory.  I would like that to run after the array has been completed and all the files have been uploaded.  Can someone point me in the right direction on this one?  Thanks for you time.

 

Ryan

Link to comment
Share on other sites

I will look at that, but my concern is that this would run every single time I would call my script.  For example, index.php calls uploads.php 300 times.  Once uploads.php has went through the array completely, I then want it to execute another portion of code just the one time to end it.

Link to comment
Share on other sites

Unless I'm missing something you shuldn't call uploads.php 300 times. Instead make the code in that page a function and then call the page once. Then in your foreach loop call the function. After the loop is complete, then do the action you want to have happen one time.

 

index.php

<?php

include ("uploads_function.php");

foreach ($imageArray as $file) {

 upload_function($file);

}

//Whatever goes here will perform once after the loop completes.

?>

Link to comment
Share on other sites

I am using a Flash Bulk Loader and it looks to me (I don't know flash) that it is passing a file via POST, then calling the .php script.  And it just does this over and over and over.  Below is the .php script it is calling.  It appears to work pretty good.  I needed something that would allow my users to upload entire directories of files without having to select them 1 by 1.

 

$uploaddir = "mages/".$ImageAuctionDate."/";

$target_encoding = "ISO-8859-1";
echo '<pre>';
if(count($_FILES) > 0)
{
$arrfile = pos($_FILES);
$uploadfile = $uploaddir . iconv("UTF-8", $target_encoding,basename($arrfile['name']));

if (move_uploaded_file($arrfile['tmp_name'], $uploadfile))
   echo "File is valid, and was successfully uploaded.\n";
   
if($aafile['name'] = $endofarray)
        {
$arrfile = pos($_FILES);
$uploadfile = $uploaddir . iconv("UTF-8", $target_encoding,basename($arrfile['name']));
}
   
}
else
{

}

Link to comment
Share on other sites

I tried foreach() and it still did not work.  So the flash uploader must be sending these images to the upload.php script individually.  Again, it works great.  I just want to run my thumnail resize script once they are all uploaded to the directory.  The uploader works great, my thumbnail script works great as well.  Now it is just a matter of getting the thumbnail script to run after all the images have been uploaded.  Any other suggestions would be appreciated.  Thanks!

Link to comment
Share on other sites

I have some scripts that i run consecutively. How I do it :I make one script out of the seveveral i.e.

all_at_once.php

<?php

ini_set (max_execution_time,600);

include_once("script1.php");

include_once("script2.php");

include_once("script3.php");

echo"finished";

?>


 

Then just run all_at_once.php

I know it's a bit simple but it works for my needs, hope it helps!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.