Hurtigt nemt spøgsmål :)

Tags:    php

Ja jeg vil bruge denne her til at uploade ind på serveren men jeg har et problem serveren jeg uploader til kender ikke fil typen jpg og gif er der nogle der kan lave det så det viker 100% personen får 200 points :)


Du kan se en test af den her på www.mpj.fastweb.dk :)



<HTML>
<HEAD>
<TITLE>Signatur Upload!!!</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">

<p align="center"> </p>
<?

### Configuration ###


# What directory should the files be uploaded to ? ( Remeber to chmod 777 your_upload_dir )
$upload_directory = "/web/www/fastweb/users/mpj";

# The Max Upload Size of a file when upload to server!
$max_upload_size = "102400"; // Set to 100 kB

# What type of files should be allowed to be uploaded ?
//$allow_type = "audio/mpeg"; // This is the tag to only allow *.MP3 files to be uploaded!
$allow_type=Array();
$allow_type[]='jpg';
$allow_type[]='gif';

# Shall the script only allow 1 file type to be uploaded ?
$allow_file_type = "1"; // Only allows 1 file to be uploaded to server!

### Font setup ###
$font = "verdana";
$font_size = "2";
$font_color = "black";

### Error Messages ###

# No file to upload
$no_file = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\">Sorry, but you didn't select a file to upload";

# File is to big
$to_big_file = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\">Sorry, but the file you have select is to big to be uploaded!";

# Not the correct filetype
$not_correct_file = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\">Sorry, but the file you tried to upload is not valid file to upload! We do not allow $type";

# Error to write file to upload directory
$error_write_file = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\">Sorry, but there has been an error processing $file_name to the
$upload_directory! Please try again later!";

# The file is already uploaded
$already_uploaded = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\">Sorry, the file already Exists on server!";


### Thank You Message(s) ###
$thank_you = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\"> http://www.mpj.fastweb.dk/$file_name";

####### Code Starting #######


if (!$file_name) die("$no_file");

if ($file_size > $max_upload_size) {
die("$to_big_file");
}

if ($allow_file_type == "1") {
if (!in_array(strrchr($file_name,'.'),$allow_type)) {
die("$not_correct_file");
}
}

if (file_exists("$upload_directory/$file_name")) {
die("$already_uploaded");
}

@copy($file, "$upload_directory/$file_name") or die("$error_write_file");

# EOF!
echo "<center><b>$thank_you";
?></font></font></font></font></font></font>

</BODY>
</HTML>



3 svar postet i denne tråd vises herunder
1 indlæg har modtaget i alt 5 karma
Sorter efter stemmer Sorter efter dato
Hej Silver,

Her er så dit lille script - komplet rettet igennem og rent faktisk testet.
Der var en del småfejl i det som skulle rettes først, men de skulle være nemme nok at finde frem til :-)

<pre>
<HTML>
<HEAD>
<TITLE>Signatur Upload!!!</title>
</head>
<BODY bgcolor="#FFFFFF">

<p align="center"> </p>

<?php
$file = $HTTP_POST_FILES['fileGetterName']['tmp_name'];
$file_name = $HTTP_POST_FILES['fileGetterName']['name'];
$file_size = $HTTP_POST_FILES['fileGetterName']['size'];
$file_type = $HTTP_POST_FILES['fileGetterName']['type'];

### Configuration ###

# What directory should the files be uploaded to ? ( Remeber to chmod 777 your_upload_dir )
# also remember that this is relative to where this script is located!!!
$upload_directory = "upload"; //"/web/www/fastweb/users/mpj";

# The Max Upload Size of a file when upload to server!
$max_upload_size = "102400"; // Set to 100 kB

# What type of files should be allowed to be uploaded ?
//$allow_type = "audio/mpeg"; // This is the tag to only allow *.MP3 files to be uploaded!
$allow_type=Array();
$allow_type[]='image/jpg'; // NOTE: real mimetype name here.
$allow_type[]='image/jpeg'; // NOTE: real mimetype name here.
$allow_type[]='image/gif';

# Shall the script only allow 1 file type to be uploaded ?
$allow_file_type = "1"; // Only allows 1 file to be uploaded to server!

### Font setup ###
$font = "verdana";
$font_size = "2";
$font_color = "black";

### Error Messages ###

# No file to upload
$no_file = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\">Sorry,
but you didn't select a file to upload";

# File is to big
$to_big_file = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\">Sorry,
but the file you have select is to big to be uploaded!";

# Not the correct filetype
$not_correct_file = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\">Sorry,
but the file you tried to upload is not valid file to upload! We do not allow $file_type";

# Error to write file to upload directory
$error_write_file = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\">Sorry,
but there has been an error processing $file_name to the $upload_directory! Please try again later!";

# The file is already uploaded
$already_uploaded = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\">Sorry,
the file already Exists on server!";

# Thank You Message(s)
$thank_you = "<b><font face=\\"$font\\" size=\\"$font_size\\" color=\\"$font_color\\">Thank you</font></b>";

####### Code Starting #######

if (!$file_name) die("$no_file");

if ($file_size > $max_upload_size) die("$to_big_file");

if ($allow_file_type == "1") {
if (!in_array($file_type, $allow_type)) die("$not_correct_file");
}

if (file_exists("$upload_directory/$file_name")) die("$already_uploaded");

@copy($file, "$upload_directory/$file_name") or die("$error_write_file");

# EOF!
echo "<center>$thank_you</center>";

</body>
</html>
</pre>
[Redigeret d. 16/12-02 14:40:57 af Johnny T. Vestergaard]



Kan du ikke lægge følgende script op på serveren og linke til det?

<?PHP echo phpinfo(); ?>

Så kan jeg se hvilke begrænsninger som er opstillet af serveren.

Men umiddelbart har du nogle helt andre problemer med din kode

Hvordan initialiserer du variablene $file_name & $file_size?
[Redigeret d. 11/12-02 18:43:56 af Erik K. Aarslew-Jensen]



Kan du ikke lægge følgende script op på serveren og linke til det?

<?PHP echo phpinfo(); ?>

Så kan jeg se hvilke begrænsninger som er opstillet af serveren.

Men umiddelbart har du nogle helt andre problemer med din kode

Hvordan initialiserer du variablene $file_name & $file_size?
[Redigeret d. 11/12-02 18:43:56 af Erik K. Aarslew-Jensen]


Ok det har jeg gjort www.mpj.fastweb.dk/info.php

Vil du ikke være sød at lave fejlene i den (det er en jeg har fundet på nettet)




t