Reply LinkBack Thread Tools Search this Thread
Old 17-07-2008, 10:42   #1 (permalink)
dawiyo
stuck in the '90s
 
dawiyo's Avatar
 
Join Date: Jun 2008
Location: Baltimore, MD, USA
Posts: 123
Need help with a PHP upload script

I've searched through the results on here for PHP upload and found mostly links for tutorials. Mind you, the tutorials are great, however, they offer no help if something doesn't work. Thus, I turn to here.

I am relatively new to PHP (okay, so I know nothing) howver a client needs this to work. All I'm looking for is a super simple upload script to upload pictures to a different folders, specified by the user, on the server. The server is a shared Unix one that supposedly has all the PHP framework and etc. installed. However, every time I try to run the script, I keep getting an Internal Server Error. I made sure to upload CHMOD (755) and everything that the tutorial included. I just can't get past this error.

Any help would be greatly appreciated.
  Reply With Quote
Old 17-07-2008, 12:05   #2 (permalink)
Shiro
Whitey
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 5,351
Code + link = potential help.
__________________
  Reply With Quote
Old 17-07-2008, 13:43   #3 (permalink)
Cborrow
I like code.
 
Join Date: Dec 2004
Location: Chesapeake, VA
Posts: 282
Send a message via AIM to Cborrow
There are a lot of free scripts you can find out there for what you need.

http://www.verot.net/php_class_upload.htm
http://www.phpsimplicity.com/scripts.php?id=3
Secure File Upload with PHP
HyperSilence.net - Silentum Uploader - PHP Upload Script

Of you can use the script below.

Just save this as something like FileUpload.php
PHP Code:
<?php
    
class FileUpload {
        public 
$MaxSize "2MB";
        public 
$AllowedExtensions "jpeg,jpg,gif,png,bmp,xbm,xpm";
        public 
$UploadDirectory "./images/";
        
        private 
$filetemp;
        private 
$filename;
        private 
$filetype;
        private 
$filesize;
        private 
$fileerror;
        private 
$fileextension;
        
        public function 
__construct($filesArray null) {
            if(isset(
$filesArray)) {
                
self::SetFileInfo($filesArray);
            }
        }
        
        public function 
SetFileInfo($filesArray) {
            if(isset(
$filesArray) && is_array($filesArray)) {
                
$this->filetemp $filesArray['tmp_name'];
                
$this->filename $filesArray['name'];
                
$this->filetype $filesArray['type'];
                
$this->filesize $filesArray['size'];
                
$this->fileerror $filesArray['error'];
                
$this->fileextension strtolower(array_pop(explode("."$this->filename)));
            }
        }
        
        public function 
Upload($uploadDir null) {
            if(isset(
$this->filetemp) && isset($this->filename) && $this->fileerror == 0) {
                if(empty(
$uploadDir)) { $uploadDir $this->UploadDirectory; }
                
                if(!
in_array($this->fileextensionexplode(","$this->AllowedExtensions))) {
                    echo 
"The file is not of a supported type, allowed types are {$this->AllowedExtensions}";
                    return 
false;
                }
                if(
$this->filesize self::ParseSize($this->MaxSize)) {
                    echo 
"File is too large, the max size is {$this->MaxSize}";
                    return 
false;
                }
                
                if(
is_uploaded_file($this->filetemp)) {
                    if(
move_uploaded_file($this->filetemp$uploadDir $this->filename)) {
                        if(
file_exists($uploadDir $this->filename)) {
                            echo 
"Your file has been uploaded";
                            return 
true;
                        }
                    }
                }
            }
            return 
false;
        }
        
        private function 
ParseSize($size) {
            
preg_match("(([0-9]+)([a-zA-Z]+))"$size$match);
            
$multiplier 1;
            
            if(
is_string($match[2])) {
                switch(
strtolower($match[2])) {
                    case 
"b":
                        
$multiplier 1;
                        break;
                    case 
"kb":
                        
$multiplier 1024;
                        break;
                    case 
"mb":
                        
$multiplier = (1024 1024);
                        break;
                    case 
"gb":
                        
$multiplier = ((1024 1024) * 1024);
                        break;
                    default:
                        
$multiplier 1;
                        break;
                }
                
                if(
is_integer((int)$match[1])) {
                    return 
$match[1] * $multiplier;
                }
            }
            return 
false;
        }
    }
?>

Then use this to upload files.
Don't forget to change "/path/to/uploadfile.php" to point to
whatever you saved the above script as.

PHP Code:
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<div>
<label>File</label>
<input type="file" name="myFile" size="30" /><br /><br />
<input type="submit" name="upload" value="Upload" />
</div>
</form>
<?php
    
if(isset($_POST['upload'])) {
        include 
"/path/to/uploadfile.php";
        
        
$upload = new FileUpload($_FILES['myFile']);
        
$upload->Upload("images/");
    }
?>
__________________

Last edited by Cborrow : 18-07-2008 at 10:44.
  Reply With Quote
Old 17-07-2008, 16:46   #4 (permalink)
urban1977
Multimedia Developer
 
urban1977's Avatar
 
Join Date: Jun 2008
Location: Cheshire
Posts: 259
this might help also

try this as an addition

http://t1.eu-guild.net/admin/_sitestyle/SWF.rar

upload swf / fla file included.

just point it at your upload php file
  Reply With Quote
Old 18-07-2008, 09:29   #5 (permalink)
dawiyo
stuck in the '90s
 
dawiyo's Avatar
 
Join Date: Jun 2008
Location: Baltimore, MD, USA
Posts: 123
Thank you Cborrow for posting those. This will show my newbness to php.

I realize that the first is for the first upload page, but what do I do with the second script? Dedicated PHP page with nothing but that?

EDIT: After trying the script with it's own dedicated page I get the following error:

Warning: preg_match() [function.preg-match]: Unknown modifier '(' in /home/u3/nrdadmin/html/UploadScript.php on line 40
Upload is too large, is the maximum
  Reply With Quote
Old 18-07-2008, 09:44   #6 (permalink)
hobolooter
Registered User
 
hobolooter's Avatar
 
Join Date: Feb 2004
Location: USA
Posts: 83
Send a message via AIM to hobolooter
Quote:
Originally Posted by dawiyo
Thank you Cborrow for posting those. This will show my newbness to php.

I realize that the first is for the first upload page, but what do I do with the second script? Dedicated PHP page with nothing but that?

EDIT: After trying the script with it's own dedicated page I get the following error:

Warning: preg_match() [function.preg-match]: Unknown modifier '(' in /home/u3/nrdadmin/html/UploadScript.php on line 40
Upload is too large, is the maximum

Is that last line truncated? I'm guessing you just need to edit your php.ini and increase your maximum file upload.
  Reply With Quote
Old 18-07-2008, 10:11   #7 (permalink)
dawiyo
stuck in the '90s
 
dawiyo's Avatar
 
Join Date: Jun 2008
Location: Baltimore, MD, USA
Posts: 123
I got the "Secure Upload with PHP" tutorial to work! So excited. However, I need the ability to upload more than 350kb. These images are coming straight from the camera and the people that will be uploading are not computer savvy.
  Reply With Quote
Old 18-07-2008, 10:41   #8 (permalink)
Cborrow
I like code.
 
Join Date: Dec 2004
Location: Chesapeake, VA
Posts: 282
Send a message via AIM to Cborrow
Change the 35000 to something like

Code:
(2 * 1024) * 1024)

That will give you 2 MB.

Edit: I also updated the script I posted before, actually tested it this time.
__________________
  Reply With Quote
Old 18-07-2008, 10:48   #9 (permalink)
dawiyo
stuck in the '90s
 
dawiyo's Avatar
 
Join Date: Jun 2008
Location: Baltimore, MD, USA
Posts: 123
Thanks man. I got it working. I want to find a simple progress loader, but with what I've accomplished today, I'm happy!

Unless you have a simple example


btw: You're not far from me! Our employees are working in chesapeake right now.
  Reply With Quote
Old 18-07-2008, 12:33   #10 (permalink)
hobolooter
Registered User
 
hobolooter's Avatar
 
Join Date: Feb 2004
Location: USA
Posts: 83
Send a message via AIM to hobolooter
PHP is a pain in the ass to write a file upload progress bar. However, I believe there are some scripts floating around the web that will work. I've never used them myself, as I've never had a need to track upload progress.

Brady » PHP File Upload Progress Bar

^^ Check that out.
  Reply With Quote
Old 18-07-2008, 12:37   #11 (permalink)
dawiyo
stuck in the '90s
 
dawiyo's Avatar
 
Join Date: Jun 2008
Location: Baltimore, MD, USA
Posts: 123
You know, just messing around with this script and everything has really made me want to learn php. w3schools it is for me!
  Reply With Quote
Old 18-07-2008, 12:44   #12 (permalink)
hobolooter
Registered User
 
hobolooter's Avatar
 
Join Date: Feb 2004
Location: USA
Posts: 83
Send a message via AIM to hobolooter
PHP is pretty much pure server side sex. You can get bugs and shit if you aren't careful, but otherwise there is nothing else like it.
  Reply With Quote
Old 18-07-2008, 13:20   #13 (permalink)
Cborrow
I like code.
 
Join Date: Dec 2004
Location: Chesapeake, VA
Posts: 282
Send a message via AIM to Cborrow
Yeah, mostly all of the file upload scripts that had a progress bar required something like Perl or another language that directly reads the HTTP output.

While looking around it looks like PHP can do it with the help of the APC_* functions and extension.

Here are a couple of progress bars to add to the one hobolooter posted.

Joshua Eichorn's Blog » Blog Archive » PHP AJAX File Upload Progress Meter Updates
SourceForge.net: Mega Upload Progress Bar
Web Reflection: Upload progress bar with PHP5, APC and jQuery
__________________
  Reply With Quote
Old 28-07-2008, 17:53   #14 (permalink)
gmwebs
Registered User
 
Join Date: Sep 2006
Posts: 3
I don't know if you have an aversion towards javascript, but I recently had a client who required a multi-upload feature and found the following (dhtmlxVault) which was dead simple to use and configure. The actual uploading and progress report is done server-side while all the prettiness comes from js and css.

I also had a look at the SWF Upload linked earlier in this thread, but it was a mission to get working to be honest and requires the Flash player on the end-user's browser.

I should add that the version with the progress bar is not free, but it is worth looking at. With a bit of ingenuity you could always implement the progress bar in the free version anyway.

I would have posted the link but it seems as if I am not allowed to add links yet
  Reply With Quote
Old 30-07-2008, 15:23   #15 (permalink)
myF1dream
Registered User
 
myF1dream's Avatar
 
Join Date: Jul 2008
Posts: 15
Try Thin Uploader

Thin Uploader as I remember was the only decent uploader I found which worked for both Mac and PC and also allowed for file sizes over 100mb.

Good Luck

Ashley
  Reply With Quote
Reply



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

Advanced Search


Contact Us - Web Design Forums - Archive
Web Hosting by Heart Internet
Search Engine Optimization by vBSEO 3.0.0 RC8
Web Hosting by Heart Internet