By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,543 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.