Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Proszeo poprawienie skryptu (FORM)
-Gość_janusz_23_*-
post 18.08.2006, 11:45:11
Post #1





Goście







wITAM!
mam problem z ograniczeniem typu przyesłynaych na serwer plikow (chcialbym zeby mozna bylo wysylac tylko jpg, gif, jpeg, doc i pdf) gdzie mam wpisac te ograniczenia w poniższym skrypcie i w jakiej formie tzn. odzielnie czy w jedym polecieniu.
Prosze o pomoc
P.S. czy ten skrypt jest bezpieczny??

<?php

$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$upload_dir = "upload_files/";
$upload_url = $url_dir."/upload_files/";
$message ="";

//create upload_files directory if not exist
//If it does not work, create on your own and change permission.
if (!is_dir("upload_files")) {
die ("upload_files directory doesn't exist");
}

if ($_FILES['userfile']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
$message = "Invalid File Specified.";
}

print $message;

function do_upload($upload_dir, $upload_url) {

$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result = $_FILES['userfile']['error'];
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;

//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
//File Size Check
else if ( $file_size > 5000000) {
$message = "The file size is over 5 MB.";
return $message;
}
//File Type Check
else if ( $file_type == "*.jpg" ) {
$message = "Sorry, You cannot upload any script file" ;
return $message;
}

$result = move_uploaded_file($temp_name, $file_path);
$message = ($result)?"File url <a href=$file_url>$file_url</a>" :
"Somthing is wrong with uploading a file.";

return $message;
}
?>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
Upload Image<input type="file" id="userfile" name="userfile">
<input type="submit" name="upload" value="Upload">
</form>







</body>
</html>
Go to the top of the page
+Quote Post
Ja_Szczur
post 18.08.2006, 11:51:34
Post #2





Grupa: Zarejestrowani
Postów: 115
Pomógł: 0
Dołączył: 4.12.2005
Skąd: Strzyżów

Ostrzeżenie: (0%)
-----


  1. <?php
  2. //File Type Check
  3. else if ( $file_type != "image/pjpeg" && $file_type != "image/gif" && ... ) {
  4. $message = "Sorry, You cannot upload any files except jpg,gif,pdf... " ;
  5. return $message;
  6. }
  7. ?>


--------------------
"No bo z fasolą to człowiek przynajmniej wie, na czym stoi..."
Pomniejsze bóstwa, Terry Pratchett

php :*
Go to the top of the page
+Quote Post
-janisz_23-
post 18.08.2006, 12:14:04
Post #3





Goście







Dziękuje za promoc!

Przypomnialo mi się jeszcze jedno. Chce zeby w formularzu było 5 pól do załadowania zdjęc. Czy wystarczy jedynie w kodzie HTMl dodać kilka pól inpute czy trzeba też zmieniać sam skrypt php??

<?php

$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$upload_dir = "upload_files/";
$upload_url = $url_dir."/upload_files/";
$message ="";

//create upload_files directory if not exist
//If it does not work, create on your own and change permission.
if (!is_dir("upload_files")) {
die ("upload_files directory doesn't exist");
}

if ($_FILES['userfile']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
$message = "Invalid File Specified.";
}

print $message;

function do_upload($upload_dir, $upload_url) {

$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result = $_FILES['userfile']['error'];
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;

//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
//File Size Check
else if ( $file_size > 5000000) {
$message = "The file size is over 5 MB.";
return $message;
}
//File Type Check
else if ( $file_type == "*.jpg" ) {
$message = "Sorry, You cannot upload any script file" ;
return $message;
}

$result = move_uploaded_file($temp_name, $file_path);
$message = ($result)?"File url <a href=$file_url>$file_url</a>" :
"Somthing is wrong with uploading a file.";

return $message;
}
?>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
Upload Image<input type="file" id="userfile" name="userfile">
<input type="submit" name="upload" value="Upload">
</form>
Go to the top of the page
+Quote Post
Ja_Szczur
post 19.08.2006, 17:17:59
Post #4





Grupa: Zarejestrowani
Postów: 115
Pomógł: 0
Dołączył: 4.12.2005
Skąd: Strzyżów

Ostrzeżenie: (0%)
-----


krypto-reklama ! ;]


--------------------
"No bo z fasolą to człowiek przynajmniej wie, na czym stoi..."
Pomniejsze bóstwa, Terry Pratchett

php :*
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 12.06.2025 - 18:33