Current location: Hot Scripts Forums » Programming Languages » PHP » Uploading file


Uploading file

Reply
  #1 (permalink)  
Old 07-23-06, 09:45 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
Angry Uploading file

I have tried several different upload scripts to upload a file 5.86MB. I had no trouble uploading a 1.75MB file but it always fails with the 5.86MB file.
I have tried scipts uploading to a directory and to a mysql database.

The only way I seem to be able to upload this file is by using an ftp program. If I can do it with ftp how come I can't with php?

Any ideas?
__________________
Aye!
Reply With Quote
  #2 (permalink)  
Old 07-23-06, 10:02 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Are you getting an error message?

There are two settings in PHP that limit the size of an upload -
Code:
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
Note: if you exceed the post_max_size, the $_FILES[...] variable won't exist at all and you must test, something like this -
PHP Code:

// check for this bug/feature in PHP -

if(!isset($_FILES['userfile'])){
    echo 
"The upload file size exceeds the POST_MAX_SIZE directive in php.ini<br />";
    die();

Here is some additional error checking and reporting you can put in your code to tell you more about what is going on -
PHP Code:

// print a status message

switch ($_FILES['userfile']['error']) {
case 
0:
echo 
"The file uploaded to the server OK<br />";
break;
case 
1:
echo 
"The uploaded file exceeds the upload maximum size directive in php.ini<br />";
break;
case 
2:
echo 
"The uploaded file exceeds {$_POST['MAX_FILE_SIZE']}, the MAX_FILE_SIZE directive in the HTML form<br />";
break;
case 
3:
echo 
"The uploaded file was only partially uploaded<br />";
break;
case 
4:
echo 
"No file was uploaded<br />";
break;
case 
6:
echo 
"Missing a temporary folder<br />";
break;
case 
7:
echo 
"Failed to write file to disk<br />";
break;
default:
echo 
"An unused error value was returned<br />";

__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???

Last edited by mab; 07-23-06 at 10:05 AM.
Reply With Quote
  #3 (permalink)  
Old 07-23-06, 11:47 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
this is the code I used and it returned "error uploading"

PHP Code:

$uploadDir 'uploads/';


if(!isset(
$_FILES['demo'])){
    echo 
"The upload file size exceeds the POST_MAX_SIZE directive in php.ini<br />";
    die();}
{
$fileName $_FILES['demo']['name'];
$tmpName $_FILES['demo']['tmp_name'];
$fileSize $_FILES['demo']['size'];
$fileType $_FILES['demo']['type'];

$filePath $uploadDir $fileName;

$result move_uploaded_file($tmpName$filePath);
if (!
$result) {
echo 
"Error uploading file";
exit;
}

echo 
"<br>Files uploaded<br>";


didn't quite understand what to do with the other list you posted
__________________
Aye!
Reply With Quote
  #4 (permalink)  
Old 07-23-06, 03:42 PM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs down

Why's it not working??????????
__________________
Aye!
Reply With Quote
  #5 (permalink)  
Old 07-24-06, 03:27 AM
duesi's Avatar
duesi duesi is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 225
Thanks: 0
Thanked 0 Times in 0 Posts
Check the settiings mab has posted earlier.
If you have no access to the php.ini file, look at the output of this:

PHP Code:

phpinfo(); 

__________________
Duesi

"One of the great skills in using any language is knowing what not to use, what not to say" (Ron Jeffries)

http://www.swissbytes.de
Reply With Quote
  #6 (permalink)  
Old 07-24-06, 05:57 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
results from phpinfo:

post_max_size: local = 8M master = 8M
upload_max_filesize: local = 2M master = 2M

I don't understand how I can drag 6MB files into frontpage and upload them from there if it says I can only upload 2MB.
__________________
Aye!
Reply With Quote
  #7 (permalink)  
Old 07-24-06, 07:18 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Deansatch
I don't understand how I can drag 6MB files into frontpage and upload them from there if it says I can only upload 2MB.
PHP and the PHP settings are only used for script files you write. PHP is a scripting language that outputs web pages. Frontpage has no connection (figuratively or literally) to PHP or the PHP settings.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #8 (permalink)  
Old 07-24-06, 08:12 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
Question

So if I can't upload large files using php, is there any other scipting laguage I could use to get the job done?
I am making a CMS site for a band and they need to be able to upload there songs to a demos page so that people can download them and have a listen. Defeats the purpose if I have to put the files on for them.
__________________
Aye!
Reply With Quote
  #9 (permalink)  
Old 07-24-06, 08:33 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
If we consult the PHP manual, we find that upload_max_filesize is changeable on a per dir basis. If you are on an Apache web server and if the hosting company has not prevented the users from setting this, you can set this using a .htaccess file.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #10 (permalink)  
Old 07-24-06, 09:23 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
I tried this htaccess file in the root and the same directory as my upload script:

<IfModule mod_php4.c>
php_value upload_max_filesize 8M
</IfModule>

Still no joy.
First time I have used htaccess. I hope I did it right.
Created file in notepad with the above content then named it ".htaccess" but had to wait until it was on the server before it would let me rename it.
Did I do wrong?
__________________
Aye!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error message not getting displayed. sanjeet Windows .NET Programming 0 12-20-05 10:48 AM
showing realtime percentage of uploading file tallpaul858 PHP 2 06-01-05 02:04 PM
checking file size before uploading sjems PHP 3 04-28-05 11:12 AM
setting a file mask for a file uploading input tag davidklonski JavaScript 0 07-07-04 06:22 AM
file uploading jaishalg PHP 1 06-22-04 11:54 AM


All times are GMT -5. The time now is 07:22 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.