473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

Atz
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
Jul 17 '05 #1
3 2488
"Atz" <ma**@mail.com> wrote:
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. $dest = $uploadpath.uniqid('img').'.gif';
$dest = $uploadpath.uniqid('img').'.jpg';
$dest = $uploadpath.uniqid('img').'.png';


And that you used uniqid() here doesn't tell you anything?

http://uk.php.net/manual/en/function.uniqid.php

JOn
Jul 17 '05 #2
Atz wrote:
case 1:
echo '<BR> Photo is GIF <BR>';
$dest = $uploadpath.uniqid('img').'.gif';
break;


Hey !

your mistake is, that you create a uniquid and
name the uploaded image this way...
If you want the image to have the original name you have to
use something like

$dest = $uploadpath.$HTTP_POST_FILES['file1']['_name'].".gif";

or you could combine the original name with a unique id to
keep from overwriting existing files with the same name.

Greetz, sandy

Jul 17 '05 #3
Atz
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaa
a

Men , what a F***

Thanx guys ...

Hear ya
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.548 / Virus Database: 341 - Release Date: 5.12.2003
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.