File upload -- completed but with errors :--)

From: Atz (mail_at_mail.com)
Date: 12/08/03


Date: Mon, 8 Dec 2003 11:56:29 +0100

Hi to all !

This is the working, completed PHP script for file upload.
The only problem is: wenn i send file and when the file is upload on the
server, the
file name ( orginal file name is bla.gif ) is converted to something like
this img34b123.gif.

The file is stored in wright directory and there is no problems with upload.
Could this be programming error or is this error/problem of the linux admin.

I have asked linux admin if there is a temp directory where the temp files
are stored, before there are uploaded, but he says no. So i cant find the
problem here...

Please take a look into the script and tell me if i made something wrong ...
----------------------------------------------------------------------------

---
<?php if ($HTTP_POST_VARS['action']) { ?>
?>
</BODY>
</HTML>
<?php } else { ?>
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="WHITE" TEXT="BLACK">
<P><FONT FACE="Arial, Helvetica, sans-serif">
 <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="<?php echo
$PHP_SELF;?>" name="bla">
   <INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="60000">
   <INPUT TYPE="HIDDEN" NAME="action" VALUE="1">
   File for upload:
   <INPUT TYPE="FILE" NAME="file1" SIZE="30">
   <INPUT TYPE="SUBMIT" VALUE="Send">
 </FORM>
</FONT></P>
</BODY>
</HTML>
<?php } ?>
<?php if ($HTTP_POST_VARS['action']) { ?>
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="WHITE" TEXT="BLACK">
<P><FONT FACE="Arial, Helvetica, sans-serif">
<?php
    $uploadpath = '/testDir/Photos/';
    $source = $HTTP_POST_FILES['file1']['tmp_name'];
    $dest = '';
    if ( ($source != 'none') && ($source != '' )) {
        $imagesize = getimagesize($source);
        switch ( $imagesize[2] ) {
            case 0:
                echo '<BR> Wrong Photo <BR>';
                break;
            case 1:
                echo '<BR> Photo is GIF <BR>';
                $dest = $uploadpath.uniqid('img').'.gif';
                break;
            case 2:
                echo '<BR> Photo is JPG <BR>';
                $dest = $uploadpath.uniqid('img').'.jpg';
                break;
            case 3:
                echo '<BR> Photo is PNG <BR>';
                $dest = $uploadpath.uniqid('img').'.png';
                break;
        }
        if ( $dest != '' ) {
            if ( move_uploaded_file( $source, $dest ) ) {
                echo 'All OK. <BR>';
            } else {
                echo 'Something was wrong.<BR>';
            }
        }
    } else {
        echo 'There is no file for upload or the file is too big.<BR>';
    }
?>
<BR>Back
</FONT></P>
</BODY>
</HTML>
<?php } else { ?>
<?php } ?>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.537 / Virus Database: 332 - Release Date: 6.11.2003


Relevant Pages

  • Possible bug? Strange problem trying to return a value from a function
    ... when the file already exists in the upload directory, ... echo $row." ... throw new Exception ("Unable to move file to upload directory. ...
    (comp.lang.php)
  • Re: file upload problem
    ... I am trying to learn about uploading files with php. ... I made a simple form script and and file up load script. ... The form script gets the file name correctly and seems to pass it to the upload script correctly. ... if I echo ini_getI see ...
    (comp.lang.php)
  • Re: file upload problem
    ... I am trying to learn about uploading files with php. ... I made a simple form script and and file up load script. ... The form script gets the file name correctly and seems to pass it to the upload script correctly. ... if I echo ini_getI see ...
    (comp.lang.php)
  • Re: FTP question
    ... > This is like asking us to guess what is the license plate on your car ... I am building a CMS that needs to upload two supporting files to ... directories on the public server. ... echo "There was a problem while uploading $file\n"; ...
    (comp.lang.php)
  • Re: file upload problem
    ... I am trying to learn about uploading files with php. ... I made a simple form script and and file up load script. ... The form script gets the file name correctly and seems to pass it to the upload script correctly. ... if I echo ini_getI see ...
    (comp.lang.php)