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><A HREF="<?php echo $PHP_SELF ?>">Back</A>
</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