Uploading files via php


 
Thread Tools Search this Thread
Top Forums Web Development Uploading files via php
# 1  
Old 08-04-2015
Uploading files via php

I used the following code, which I found on the internet to upload files.
Code:
<!-- 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" />
</form>

and
Code:
 ?php
        session_start();
        $REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
        $uniq = session_id();
        $UNIQ= `echo $uniq |cut -c3-10`;
        $UNIQ= rtrim($UNIQ);
        $MAX_FILE_SIZE=rtrim($_POST['MAX_FILE_SIZE']);

//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">
<tr>
    <td align="Center" colspan="2"><font color="#009900"><b>Upload Successful</b                                    ></font></td>
</tr>
<tr>
    <td align="right"><b>File Name: </b></td>
    <td align="left">$theFileName</td>
</tr>
<tr>
    <td align="right"><b>File Size: </b></td>
    <td align="left">$theFileSize</td>
</tr>
<tr>
    <td align="right"><b>Directory: </b></td>
    <td align="left">$uploaddir</td>
</tr>
</table>

UPLS;

    } else {

//PRINT AN ERROR IF THE FILE COULD NOT BE COPIED
echo <<<UPLF
<table cellpadding="5" width="80%">
<tr>
<td align="Center" colspan="2"><font color=\"#C80000\"><b>File could not be uploaded</b></font></td>
</tr>

</table>

UPLF;
    }
}

?>
#

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  
Old 08-04-2015
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  
Old 08-04-2015
Well, its on SCO, so it has to be different. Its all in /usr/lib/php/php.ini
Smilie
This User Gave Thanks to jgt For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

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 Whatbox.ca 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 multiupload.com

Hi Please help me writing a shell script for multiupload. result should look like: $ ./multiupload.sh /tmp/file.avi http://www.multiupload.com/P1R9BZ4X3Q http://i.imgur.com/a2vhH.png 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 qmerev2002.zip: Permission denied, what is my problem?? I am able to load other files and folders fine. (3 Replies)
Discussion started by: CoastGuard1970
3 Replies
Login or Register to Ask a Question