PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 6th, 2012, 03:05 PM
edowney edowney is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 3 edowney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 27 sec
Reputation Power: 0
PHP-General - Problems with move_uploaded_file

Hi Folks,

I'm trying to create an upload page on one of my websites. It works but only up to file sizes of 100k. I'm using move_uploaded_file and, like I said, it works fine with files that are less than 100k. I ran phpinfo on the site and it listed the max_file_uploads as 20 which I'm guessing means I should be able to upload files up to 20MB right? Any suggestions would be very helpful. The error I'm getting is "Notice: Undefined offset: 0 in /hsphere/local/home/c336918/netfedcu.org/admin/uploader.php on line 25"

Thanx!

Reply With Quote
  #2  
Old October 6th, 2012, 03:06 PM
ptr2void ptr2void is offline
I haz teh codez!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2003
Posts: 2,476 ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 5 h 9 m 5 sec
Reputation Power: 2194
Looks like on line 25 of the file "uploader.php" you are accessing the 0th index of an array which has no 0th index.

Without code, that's the best we can do.
__________________
I ♥ ManiacDan & requinix

This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!

Reply With Quote
  #3  
Old October 6th, 2012, 04:03 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 43 m 47 sec
Reputation Power: 6991
max_file_uploads is the number of file uploads allowed, it has nothing to do with the size.

upload_max_filesize and post_max_size both control how large your file uploads can be.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Last edited by E-Oreo : October 6th, 2012 at 08:17 PM.

Reply With Quote
  #4  
Old October 6th, 2012, 05:22 PM
edowney edowney is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 3 edowney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 27 sec
Reputation Power: 0
While I know you really can't say much without the code I don't think it's coding issue - but here it is.

<?php include 'passwordProtectPage.php'; ?>
<?php
require_once 'template.php';
echo head('NET Federal Credit Union Website Administration');
?>
<?php
echo nav();
?>
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);

$target_path = "../download/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

echo "<div class='art-content-layout'><div class='art-content-layout-row'><div class='art-layout-cell art-content'><div class='art-post'><div class='art-post-body'><div class='art-post-inner art-article'><h2 class='art-postheader'>Newsletter Upload Management</h2><div class='art-postcontent'>";

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again! [" . $target_path . "]";
$html_body = '<h1>File upload error!</h1>';
switch ($_FILES[0]['error']) {
case 1:
$html_body .= 'The file is bigger than this PHP installation allows';
break;
case 2:
$html_body .= 'The file is bigger than this form allows';
break;
case 3:
$html_body .= 'Only part of the file was uploaded';
break;
case 4:
$html_body .= 'No file was uploaded';
break;
default:
$html_body .= 'unknown errror';
}
echo ($html_body);
}

echo "</div></div></div></div></div></div></div>";
?>

How can I verify what the largest file size that can be uploaded? phpinfo doesn't have that info. I can upload files up to 100k and then I get that error message. It worked correctly at one time. I have a client who uploads their PDF newsletters using this (and the initial form that allows them to select the file this is the code that actually uploads). Thanks for your help! If there's another way to upload files via php that would make more sense I'm all ears.

Reply With Quote
  #5  
Old October 6th, 2012, 08:15 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 43 m 47 sec
Reputation Power: 6991
Something like
PHP Code:
<?php
echo min(ini_get('upload_max_filesize'), ini_get('post_max_size')) . ' bytes';

Reply With Quote
  #6  
Old October 6th, 2012, 09:08 PM
edowney edowney is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 3 edowney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 27 sec
Reputation Power: 0
Thanks - that at least helped verify the file size I can upload. So I ran it and the answer is 20M Bytes. Still it seems odd that I can upload files that are less than 100k but nothing larger and I know when I implemented it I was uploading 600k files. Any other suggestions would be greatly appreciated.

Reply With Quote
  #7  
Old October 7th, 2012, 12:54 AM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 43 m 47 sec
Reputation Power: 6991
If it gave you '20M' as the output it might not be accurate; I was expecting it to normalize the values to integer bytes but I guess it didn't. You should output them separately and compare them visually instead.

Regardless, if you fix your switch statement the notice will go away and you might get useful error output:
PHP Code:
switch ($_FILES['uploadedfile']['error']) { 


Since it isn't throwing an error about $_FILES['uploadedfile'] being undefined you're not exceeding post_max_size, but you might still be exceeding upload_max_filesize. If that's the case it should give you error 1 after you fix the switch.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Problems with move_uploaded_file

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap