dlebowski Posted September 8, 2007 Share Posted September 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
marcus Posted September 8, 2007 Share Posted September 8, 2007 //do this first sleep(10); //relax the script for 10 seconds //do second thing Quote Link to comment Share on other sites More sharing options...
dlebowski Posted September 8, 2007 Author Share Posted September 8, 2007 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. Quote Link to comment Share on other sites More sharing options...
marcus Posted September 8, 2007 Share Posted September 8, 2007 Once the part before the sleep(10); line occurs all that data will be loaded. And after 10 seconds of cooling down, the part after that line will load then. Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 8, 2007 Share Posted September 8, 2007 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. ?> Quote Link to comment Share on other sites More sharing options...
dlebowski Posted September 8, 2007 Author Share Posted September 8, 2007 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 { } Quote Link to comment Share on other sites More sharing options...
dlebowski Posted September 8, 2007 Author Share Posted September 8, 2007 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! Quote Link to comment Share on other sites More sharing options...
harristweed Posted September 8, 2007 Share Posted September 8, 2007 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.