vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Looping a block of code. (https://vborg.vbsupport.ru/showthread.php?t=102877)

Red Blaze 12-13-2005 05:16 PM

Looping a block of code.
 
Code:

<?php
$username = $_SESSION['MM_Username'];
  $times = $_POST['times'];

for ($counter = 1; $counter < $times + 1; $counter++)
{
if ($HTTP_POST_FILES['file$counter']['size'] <= 0)
        {
                print "<b>File Not Saved</b><BR>";
                print "Because your file was over 2 MB, it wasn't recieved.<br>";
        }
        else
        {
$tempFile = $HTTP_POST_FILES['file$counter']['tmp_name'];
$destination = "/****/*******/public_html/photos/$username/" .
        $HTTP_POST_FILES['file$counter']['name'];
copy($tempFile, $destination);
                print "<b>Your File has been accepted</b><br>";
        }
}

?>

$times is the number of times I want the block of code to repeat itself.
'file$counter' has to be in order, such as 1, 2, 3... all the way to the specified number in the $times value.

Now, the loop works fine, however, no matter what it won't upload anything.

noppid 12-13-2005 05:25 PM

Does the $username folder exist and is it writable?

And, using copy() it expects to find the $HTTP_POST_FILES['file$counter']['tmp_name'] in the current folder when it is actually buffered in memory and not on disk if I'm reading the functions correcty.

Andrew 12-13-2005 05:37 PM

I think you might need to change all instances of this:
PHP Code:

$HTTP_POST_FILES['file$counter'

To this since $counter is a variable:
PHP Code:

$HTTP_POST_FILES['file' $counter


Red Blaze 12-13-2005 05:37 PM

--CURRENTLY TESTING ANDREW'S POST--

In my case $username = Red Blaze. And that Directory does exist.

I tested it like this:
Code:

if ($HTTP_POST_FILES['file1']['size'] <= 0)
        {
                print "<b>File Not Saved</b><BR>";
                print "Because your file was over 2 MB, it wasn't recieved.<br>";
        }
        else
        {
$tempFile = $HTTP_POST_FILES['file1']['tmp_name'];
$destination = "/****/*******/public_html/photos/$username/" .
        $HTTP_POST_FILES['file1']['name'];
copy($tempFile, $destination);
                print "<b>Your File has been accepted</b><br>";
        }

That's without the looping. It only uploaded the file that came from form "file1". I don't really want to add the block of code 10 times (which is the limit of uploading forms, btw). The forms are using the same looping function.

Code:

This is the code in the uploading forms page.

  <?php
  $times = $_POST['times'];

for ($counter = 1; $counter < $times + 1; $counter++)
{
print "<tr>
      <td align=\"right\">File $counter</td>
        <td><input name=\"file$counter\" type=\"file\" id=\"file$counter\" /></td>
    </tr>";
}

  ?>


noppid 12-13-2005 05:39 PM

Quote:

Originally Posted by Andrew
I think you might need to change all instances of this:
PHP Code:

$HTTP_POST_FILES['file$counter'

To this since $counter is a variable:
PHP Code:

$HTTP_POST_FILES['file' $counter


Good catch!

Andrew 12-13-2005 05:43 PM

Thanks - I made that mistake so many times when I first started coding that it's become the first thing I check now when my scripts don't work :p

Red Blaze 12-13-2005 05:45 PM

lol Andrew thanks a ton. Now I learned my lesson. :D


All times are GMT. The time now is 08:59 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01739 seconds
  • Memory Usage 1,735KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (4)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete