Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-13-2005, 05:16 PM
Red Blaze's Avatar
Red Blaze Red Blaze is offline
 
Join Date: Jan 2003
Location: Texas
Posts: 493
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 12-13-2005, 05:25 PM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 12-13-2005, 05:37 PM
Andrew's Avatar
Andrew Andrew is offline
 
Join Date: Nov 2004
Location: Pennsylvania
Posts: 441
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #4  
Old 12-13-2005, 05:37 PM
Red Blaze's Avatar
Red Blaze Red Blaze is offline
 
Join Date: Jan 2003
Location: Texas
Posts: 493
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

--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>";
}

  ?>
Reply With Quote
  #5  
Old 12-13-2005, 05:39 PM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #6  
Old 12-13-2005, 05:43 PM
Andrew's Avatar
Andrew Andrew is offline
 
Join Date: Nov 2004
Location: Pennsylvania
Posts: 441
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #7  
Old 12-13-2005, 05:45 PM
Red Blaze's Avatar
Red Blaze Red Blaze is offline
 
Join Date: Jan 2003
Location: Texas
Posts: 493
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

lol Andrew thanks a ton. Now I learned my lesson.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:52 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.04182 seconds
  • Memory Usage 2,226KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete