NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP File Upload error

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-04-2005, 04:19 PM THREAD STARTER               #1 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)

Awful PHP File Upload error


Hi,

I'm getting an error with this file upload. My form tag has that enctype="multipart/formdata" in it, and input type="file", yada yada yada... all been set up, but here's the code:

PHP Code:
//tmp location.
copy ($_FILES['file']['tmp_name'], $_FILES['file']['name']) or die ('Could not upload');

if (
$file != "")
{

$file $HTTP_POST_FILES['filename']['tmp_name'];
$file_name $HTTP_POST_FILES['filename']['name'];
????: NamePros.com http://www.namepros.com/programming/112676-php-file-upload-error.html
$file_size $HTTP_POST_FILES['filename']['size'];
$file_type $HTTP_POST_FILES['filename']['type'];
$file_error $HTTP_POST_FILES['filename']['error'];

if (
$file_error 0)
{
    echo 
"Problem: ";
    switch (
$file_error)
    {
        case 
1display_error('File is too big. Max size is 3 MB.'); break;
????: NamePros.com http://www.namepros.com/showthread.php?t=112676
        case 
2display_error('File is too big. Max size is 3 MB.'); break;
        case 
3display_error('The file was only partially uploaded.'); break;
        case 
4display_error('The file did not upload.'); break;
    }
    exit;
}

if (
$file_type != "zip")
{
    echo(
' >>> '.$file_type.' <<< ');
    
display_error('That is not a valid file. File extention must be .zip.');
}

if (
$file_size $MAX_FILE_SIZE)
{
    
display_error('File is too large - maximum size allowed is 3 MB.');
}

//put the file where we want it.
$location '/home/***/public_html/flonds/**/**/**/**/**/'.$file_name;

if (
is_uploaded_file($filename))
{
    if (!
move_uploaded_file($filename$upfile))
    {
        
display_error('Could not move file to directory.');
    }
}
else
{
    
display_error('Problem: Possible file upload attack. Filename: '.$file_name);
}

I have the pathname scrambled just for privacy's sake.

My idea was to try copying it to a temporary location (2nd line) but that doesn't work, and I get the error as early in the script as that.

Any help appreciated. Thanks. (This is my first PHP file upload)
mholt is offline  
Old 08-04-2005, 05:09 PM   #2 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
are you using php 4.1.0 or newer if so use $_FILES instead of $HTTP_POST_FILES

Also when copying the file where are you trying to copy it too? ensure you use a proper server path so that the script knows EXACTLY where to copy it, also ensure you have write permissions for that directory (ie chmod the directory). There is no need to copy the temp file only to have to move it elsewhere anyway, this is just creating extra work. The file should not delete from the temp folder until the script is terminated.
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Last edited by filth; 08-04-2005 at 05:16 PM.
Peter is offline  
Old 08-04-2005, 05:29 PM THREAD STARTER               #3 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Yes, I'm using PHP 4.3... but does it really MATTER? If so, I will use the new form... that you suggest.

I am sure the server path is correct, CHMOD is correct, etc... etc...
mholt is offline  
Old 08-04-2005, 07:14 PM   #4 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
the $HTTP_etc global variables are deprecated ie in a future version they may not exist, $_FILES will be around long after $HTTP_POST_FILES

in the following line:-
PHP Code:
copy ($_FILES['file']['tmp_name'], $_FILES['file']['name']) or die ('Could not upload'); 
????: NamePros.com http://www.namepros.com/showthread.php?t=112676
where are you intending to copy this file? why copy it in the first place you are moving it later anyway?
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Old 08-04-2005, 07:23 PM THREAD STARTER               #5 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
I dunno... I was just trying stuff...
mholt is offline  
Old 08-05-2005, 02:36 AM   #6 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough
 


Breast Cancer
can u post your html form and copy all errors you see.
adam_uk is offline  
Old 08-05-2005, 07:21 AM   #7 (permalink)
NamePros Member
 
Icespadez's Avatar
Join Date: Apr 2005
Location: Boston, MA
Posts: 26
Icespadez is an unknown quantity at this point
 



PHP Code:
    if (isSet($_FILES['file'])) {
        if (
is_uploaded_file($_FILES['file']['tmp_name'])) {
            if (
$_FILES['file']['error'] > 0) {
                switch (
$_FILES['file']['error'])
                {
                    case 
1:
                        exit(
'File is too big. Max size is 3 MB.');
                        break;
                    case 
2:
                        exit(
'File is too big. Max size is 3 MB.');
                        break;
                    case 
3:
                        exit(
'The file was only partially uploaded.');
                        break;
                    case 
4:
                        exit(
'The file did not upload.');
                        break;
                }
            }
            if (
$_FILES['file']['type'] != 'zip') {
                exit(
$_FILES['file']['type'] . ' is not a valid extension. File extention must be .zip.');
            }
            if (
$_FILES['file']['size'] > '3072') {
                exit(
'File is too large - maximum size allowed is 3 MB.');
            }

            
$location '/home/***/public_html/flonds/**/**/**/**/**/' $_FILES['file']['name'];
????: NamePros.com http://www.namepros.com/showthread.php?t=112676

            if (
move_uploaded_file($_FILES['file']['tmp_name'], $location)) {
                echo 
'Upload Successful';
            } else {
                exit(
'Could Not Move Uploaded File');
????: NamePros.com http://www.namepros.com/showthread.php?t=112676
            }
        } else {
            exit(
'File Not Uploaded');
        }
    } 
Icespadez is offline  
Old 08-05-2005, 07:38 AM THREAD STARTER               #8 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Thanks, Icespadez! It works!

Although, the filesize '3072' is not 3 MB - that's 3.072 KB lol or 30.72 O.o... but I fixed that Thanks!!!
mholt is offline  
Closed Thread


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 10:09 AM
Tutorial: How to Install Apache2 MySQL and PHP on Windows deadserious Webmaster Tutorials 35 09-21-2005 10:46 PM
2 Huge Name Forsale Vegas Entertainment Domains For Sale - Make Offer 9 09-21-2004 03:37 PM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 02:43 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger