Visit The New, Modern Unix Linux Community

Uploading files via php

Thread Tools Search this Thread
Top Forums Web Development Uploading files via php
# 1  
Uploading files via php

I used the following code, which I found on the internet to upload files.
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="upload2.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="8000000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />

        $uniq = session_id();
        $UNIQ= `echo $uniq |cut -c3-10`;
        $UNIQ= rtrim($UNIQ);

//The files have a link on a page for downloading
//and filenames are also put in the progress bar so
//the file can be viewed in the browser (ie. PDF files)
//so replace a few characters.  Since the file links are
//loaded onto another page via php and filenames
//are displayed, I wanted to use this method instead
//of url_encode() [just looks funny when displayed]

$SafeFile = $_FILES['userfile']['name'];
$SafeFile = str_replace("#", "No.", $SafeFile);
$SafeFile = str_replace("$", "Dollar", $SafeFile);
$SafeFile = str_replace("%", "Percent", $SafeFile);
$SafeFile = str_replace("^", "", $SafeFile);
$SafeFile = str_replace("&", "and", $SafeFile);
$SafeFile = str_replace("*", "", $SafeFile);
$SafeFile = str_replace("?", "", $SafeFile);

 `echo $SafeFile >>/tmp/file.log`;
$uploaddir = "/u/payroll/uploads/";
$path = $uploaddir.$SafeFile;
 `echo $path >>/tmp/file.log`;
if($userfile != none){ //AS LONG AS A FILE WAS SELECTED...

    if(copy($_FILES['userfile']['tmp_name'], $path)){ //IF IT HAS BEEN COPIED...

        //GET FILE NAME
        $theFileName = $_FILES['userfile']['name'];

        //GET FILE SIZE
        $theFileSize = $_FILES['userfile']['size'];

        if ($theFileSize>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB
            $theDiv = $theFileSize / 1000000;
            $theFileSize = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces)
        } else { //OTHERWISE DISPLAY AS KB
            $theDiv = $theFileSize / 1000;
            $theFileSize = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces)

echo <<<UPLS
<table cellpadding="5" width="300">
    <td align="Center" colspan="2"><font color="#009900"><b>Upload Successful</b                                    ></font></td>
    <td align="right"><b>File Name: </b></td>
    <td align="left">$theFileName</td>
    <td align="right"><b>File Size: </b></td>
    <td align="left">$theFileSize</td>
    <td align="right"><b>Directory: </b></td>
    <td align="left">$uploaddir</td>


    } else {

echo <<<UPLF
<table cellpadding="5" width="80%">
<td align="Center" colspan="2"><font color=\"#C80000\"><b>File could not be uploaded</b></font></td>




Even though the max file size is set at 8mb, the script fails at files sizes over 1.5mb
Are their limitations within apache, or php that can override the value in the script?
# 2  
The configuration value which controls it appears to be upload_max_filesize, not MAX_FILE_SIZE. You can find the files under /etc/php, which has two config file folders, one for commandline php, one for web server php.
# 3  
Well, its on SCO, so it has to be different. Its all in /usr/lib/php/php.ini
This User Gave Thanks to jgt For This Post:

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #148
Difficulty: Easy
A free derivative of BSD Unix, 1992BSD, was released in 1992 and led to the NetBSD and FreeBSD projects.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Plowshare Command In Uploading Files

OK i am completely new to this stuff!! let me start from the beginning!!! I Am connected to Via SSH!! Then I installed plowshare using their guide perfectly Now They Told Me To refer Plowshare site's Command list for uploading any files to Various... (4 Replies)
Discussion started by: anime12345
4 Replies

2. UNIX and Linux Applications

Need help on uploading Video files on Mediawiki and embed to page

I am working on to uploading Video files on Mediawiki and embed to page but not getting success. I tried plugin like MediaPlayer and HTML5Player but these plugins seems having extension limitation as i need to embed files like .wmv, .mpg etc. I am using mediawiki1.17 and CentOS5.8 x64 bit ... (1 Reply)
Discussion started by: sunnysthakur
1 Replies

3. UNIX for Advanced & Expert Users

Shell Script for uploading files to

Hi Please help me writing a shell script for multiupload. result should look like: $ ./ /tmp/file.avi There seems to be no official API. (3 Replies)
Discussion started by: slashdotweenie
3 Replies

4. UNIX for Dummies Questions & Answers

Uploading files from Mac to Unix/Linux via ssh

Ok. I am using the Terminal window to ssh into a unix server. I am not sure how to copy a file from my mac onto the unix server. What command do I enter and how do I type the file I want to upload Example. Say my file is named Test1.doc and it is on the usr/me/test/working/ directory and I want... (3 Replies)
Discussion started by: libertyforall
3 Replies

5. Shell Programming and Scripting

to block the files uploading via the port

Hi Folks, I am not good in shell scripting. Please help me with my problem. Is it possible to block the file named "ss.cgi" using the port 25 to upload. (4 Replies)
Discussion started by: gsiva
4 Replies

6. UNIX for Advanced & Expert Users

Uploading files in chronological order

Thanks for your help. (3 Replies)
Discussion started by: circuit.muni
3 Replies

7. Shell Programming and Scripting

Simple script uploading *.dem files to an ftp

Hello.. i want to create a simple script that's upload all the *.dem files from one directory to ftp and then delete them. Any help? (3 Replies)
Discussion started by: TuXaKoS
3 Replies

8. UNIX for Advanced & Expert Users

Perl Uploading Files

Using perl 5.8.0, Linux 2.4.20-30.9, RedHat 9.0. We have many .cgi's that allow privileged users to upload files to the server through a web browser. We've had these .cgi's for years and have never had any problems with them. Recently the files being uploaded are sometimes being given 600... (16 Replies)
Discussion started by: sstevens
16 Replies

9. UNIX for Dummies Questions & Answers

uploading Zipped files get 553 error

I am trying to upload .zip files to Unix server and get the error 553 Permission denied, what is my problem?? I am able to load other files and folders fine. (3 Replies)
Discussion started by: CoastGuard1970
3 Replies

Featured Tech Videos