Du befindest Dich im Archiv vom ABAKUS Online Marketing Forum. Hier kannst Du Dich für das Forum mit den aktuellen Beiträgen registrieren.

Upload Skript -> Bilder Skript?

Ajax, Hijax, Microformats, RDF, Markup, HTML, PHP, CSS, MySQL, htaccess, robots.txt, CGI, Java, Javascript usw.
Neues Thema Antworten
Punic@
PostRank 1
PostRank 1
Beiträge: 4
Registriert: 22.06.2006, 15:16

Beitrag von Punic@ » 22.06.2006, 15:19

Hallo,

Ich wollt fragen ob es möglich wäre bei diesem Skript unter meinem Text einen Schutz reinzumachen der nur .gif und .jpg und .jpeg und viell. noch andere erlaubt? :cry: Das Skript find ich halt übersichtlich und alles wäre net für Hilfe :wink: :arrow: THX

Code: Alles auswählen

<?php


// CSS-Style&#58;
$cssstyle =
'<style type="text/css"><!--
a&#58;link&#123;color&#58;#000000;&#125;
a&#58;visited&#123;color&#58;#999999;&#125;
a&#58;hover&#123;color&#58;#999999;&#125;
a&#58;active&#123;color&#58;#f999999;&#125;
--></style>';


//**************************************************************
// Programm&#58;
//**************************************************************

echo "$cssstyle";

// Links on Top
head&#40;&#41;;

// Startsite

// Get $path & $action
if &#40;$SubmitDir || $SubmitUpload&#41;
&#123;$path = $chosenpath;&#125;
else
&#123;$path = $_GET&#91;"path"&#93;;&#125;

$action = $_GET&#91;"action"&#93;;

// choose downloadpath
if &#40;$action == "download" && $path == ''&#41;
&#123;
$all_dirs = get_all_dirs&#40;&#41;;
choose_download_dir&#40;$all_dirs&#41;;
&#125;

// choose downloadfile
if &#40;$action == "download" && $path != ''&#41;
&#123;
$all_dirs = get_all_dirs&#40;&#41;;
choose_download_dir&#40;$all_dirs&#41;;
$all_files = listen_dir&#40;$path&#41;;
choose_download&#40;$all_files, $path&#41;;
&#125;

// choose upload
if &#40;$action == "upload" && !$SubmitUpload&#41;
&#123;
$all_dirs = get_all_dirs&#40;&#41;;
choose_upload&#40;$all_dirs&#41;;
&#125;

// do upload
if &#40;$SubmitUpload&#41;
&#123;
upload&#40;$path&#41;;


&#125;

// Links on bottom
foot&#40;&#41;;


//**************************************************************
// Functions&#58;
//**************************************************************

function head&#40;&#41;
&#123;
echo '
<html>
<head>
<title>Upload/Download</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<font face="tahoma">
<div align="center"> <a href="';
echo "$PHP_SELF";
echo '?action=">Startseite</a> | <a href="';
echo "$PHP_SELF";
echo '?action=download">Download</a>
| <a href="';
echo "$PHP_SELF";
echo'?action=upload">Upload</a> </div>
';
&#125;

function foot&#40;&#41;
&#123;
echo '
</font>
</body>
</html>
';
&#125;

function choose_download_dir&#40;$all_dirs&#41;
&#123;
echo '<br><div align="center">';
echo "Choose Directory for Download&#58;";
echo '<form name="form1" method="post" action="';
echo "$PHP_SELF?action=download";
echo '">';
echo '<select name="chosenpath">';

for &#40;$i = 0; $i < count&#40;$all_dirs&#41;; $i++&#41;
&#123;
echo '<option>';
echo "$all_dirs&#91;$i&#93;";
echo '</option>';
&#125;

echo '</select>';
echo '   ';
echo '<input type="submit" name="SubmitDir" value="Choose" class="SB_button">';
echo '</form></div>';
&#125;

function choose_download&#40;$all_files, $path&#41;
&#123;
echo '<table width="90%" border="0" align="center" bordercolor="#000000">
<tr>
<td><font face=tahoma size=2><b>Filename&#58;</b></font></td>
<td><font face=tahoma size=2><b>Size&#58;</b></font></td>
<td><font face=tahoma size=2><b>Date&#58;</b></font></td>
</tr>
<tr>
<td><font face=tahoma size=2></font></td>
<td><font face=tahoma size=2></font></td>
<td><font face=tahoma size=2></font></td>
</tr>';
for &#40;$i = 0; $i < count&#40;$all_files&#41;; $i++&#41;
&#123;
if &#40;$bgcolor == "#CCCCCC"&#41; &#123;$bgcolor = "#FFFFFF";&#125;
else &#123;$bgcolor = "#CCCCCC";&#125;
$file = $path . "/" . $all_files&#91;$i&#93;;
$file_date = @date&#40;"d.m.Y", filemtime&#40;$file&#41;&#41;;
$file_size = &#40;int&#41;&#40;filesize&#40;$file&#41;/2048&#41;;
if &#40;$file_date == "01.01.1970"&#41; &#123;$file_date = "-";&#125;

echo "<tr bgcolor=$bgcolor>
<td><font face=tahoma size=2><a href=$file>$all_files&#91;$i&#93;</a></font></td>
<td><font face=tahoma size=2>$file_size KB</font></td>
<td><font face=tahoma size=2>$file_date</font></td>";
&#125;
echo '</table>';
&#125;

function listen_dir&#40;$dir&#41;
&#123;
$dir .= "/";
if &#40;file_exists&#40;$dir&#41;&#41;
&#123;
!$opendir = opendir&#40;$dir&#41;;
$i = 0;
while &#40;$file = readdir&#40;$opendir&#41;&#41;
&#123;
$ext = strrchr&#40;$file,'.'&#41;;
if &#40;$ext != '' && $file != '.' && $file != '..'&#41;
&#123;
$all_files&#91;$i&#93; = $file;
$i++;
&#125;
&#125;
closedir&#40;$opendir&#41;;
return $all_files;
&#125;
&#125;

function get_all_dirs&#40;&#41;
&#123;
$verz=opendir &#40;'.'&#41;;
$i = 0;
while &#40;$file = readdir &#40;$verz&#41;&#41;
&#123;
if&#40;is_dir&#40;$file&#41; && $file != "." && $file != ".."&#41;
&#123;
$all_dirs&#91;$i&#93; = $file;
$i++;
&#125;
&#125;
closedir&#40;$verz&#41;;
return $all_dirs;
&#125;

function choose_upload&#40;$all_dirs&#41;
&#123;
echo '<br><div align="center">';
echo "Choose Directory for Upload&#58;";
echo '<form enctype="multipart/form-data" name="form1" method="post" action="';
echo "$PHP_SELF?action=upload";
echo '">';
echo '<select name="chosenpath">';

for &#40;$i = 0; $i < count&#40;$all_dirs&#41;; $i++&#41;
&#123;
echo '<option>';
echo "$all_dirs&#91;$i&#93;";
echo '</option>';
&#125;

echo '</select>';
echo '<p>Choose File for Upload&#58;<p>';

for &#40;$i = 0; $i <5; $i++&#41;
&#123;
echo '<input type="file" name="uploadfile';
echo "$i";
echo' "><br>';
&#125;

echo '<p><input type="submit" name="SubmitUpload" value="Upload" class="formbutton">';
echo '</form></div>';
&#125;

function upload&#40;$path&#41;
&#123;
echo "<p>";
foreach &#40;$_FILES as $upfile_info&#41; &#123;
if &#40;&#40;$file_name=$upfile_info&#91;'name'&#93;&#41;!=''&#41; &#123;
$file_name = stripslashes&#40;$file_name&#41;;
$file_name = str_replace&#40;"'","",$file_name&#41;;
$dest_location=$path."/".$file_name;
$ext = strrchr&#40;$file_name,'.'&#41;;
if &#40;!file_exists&#40;$dest_location&#41; && &#40;$ext != ".php"&#41;&#41;
&#123;
$copy = copy&#40;$upfile_info&#91;'tmp_name'&#93;, $dest_location&#41;;
&#125;
else &#123;$MSG = "File already exists or Fileextension not allowed!";&#125;
$type=$upfile_info&#91;'type'&#93;;
$size=&#40;int&#41;&#40;$upfile_info&#91;'size'&#93;/1024&#41;;
$MSG="<b>$dest_location</b> &#40;mime&#58; $type | size&#58; $size KB&#41;";
echo "<div align=center><font size=2>Successfully uploaded file&#58; $MSG</font></div><br>";
&#125;
&#125;

&#125;


?>

Anzeige von ABAKUS

von Anzeige von ABAKUS »


Hochwertiger Linkaufbau bei ABAKUS:
  • Google-konformer Linkaufbau
  • nachhaltiges Ranking
  • Linkbuilding Angebote zu fairen Preisen
  • internationale Backlinks
Wir bieten Beratung und Umsetzung.
Jetzt anfragen: 0511 / 300325-0

haha
PostRank 9
PostRank 9
Beiträge: 1065
Registriert: 03.04.2006, 18:08
Wohnort: Bi Hamborg

Beitrag von haha » 22.06.2006, 17:46

Punic@ hat geschrieben:Ich wollt fragen ob es möglich wäre bei diesem Skript unter meinem Text einen Schutz reinzumachen der nur .gif und .jpg und .jpeg und viell. noch andere erlaubt?
Ganz am Ende ist die Funktion, die Dateien entgegennimmt. Eine (billige) Sperrung an Hand der Dateiendung ist in Zeile 9 schon eingebaut:

Code: Alles auswählen

01 function upload&#40;$path&#41; &#123;
02	echo "<p>";
03	foreach &#40;$_FILES as $upfile_info&#41; &#123;
04	if &#40;&#40;$file_name=$upfile_info&#91;'name'&#93;&#41;!=''&#41; &#123;
05		$file_name = stripslashes&#40;$file_name&#41;;
06		$file_name = str_replace&#40;"'","",$file_name&#41;;
07		$dest_location=$path."/".$file_name;
08		$ext = strrchr&#40;$file_name,'.'&#41;;
09		if &#40;!file_exists&#40;$dest_location&#41; && &#40;$ext != ".php"&#41;&#41; &#123;
10			$copy = copy&#40;$upfile_info&#91;'tmp_name'&#93;, $dest_location&#41;;
11		&#125;
12		else &#123;
13			$MSG = "File already exists or Fileextension not allowed!";
14		&#125;
15		$type=$upfile_info&#91;'type'&#93;;
16		$size=&#40;int&#41;&#40;$upfile_info&#91;'size'&#93;/1024&#41;;
17		$MSG="<b>$dest_location</b> &#40;mime&#58; $type | size&#58; $size KB&#41;";
18		echo "<div align=center><font size=2>Successfully uploaded file&#58; $MSG</font></div><br>";
19	&#125;
20 &#125;
Du kannst diese Deinem Wunsch nach umbauen, indem Du in Zeile 9 '($ext != ".php")' durch 'in_array(strtolower($ext), Array(".gif", ".jpeg", ".jpg", ".png"))' ersetzt. Vorsicht, nicht die vielen Klammern verschludern, die komplette Zeile sähe dann so aus:

Code: Alles auswählen

if &#40;!file_exists&#40;$dest_location&#41; && in_array&#40;strtolower&#40;$ext&#41;, Array&#40;".gif", ".jpeg", ".jpg", ".png"&#41;&#41;&#41; &#123;
Das ist aber wie gesagt die billige Lösung. Willst Du wirklich sichergehen, dass da Bilder ankommen und nicht irgendwelche Dateien, die nur einen Namen haben, der nach einem Bild aussieht, musst Du auf die Funktion mime_content_type() zurückgreifen:

Code: Alles auswählen

if &#40;!file_exists&#40;$dest_location&#41; 
	&& in_array&#40;strtolower&#40;$ext&#41;, Array&#40;".gif", ".jpeg", ".jpg", ".png"&#41;&#41;
	&& in_array&#40;mime_content_type&#40;$upfile_info&#91;'tmp_name'&#93;&#41;, Array&#40;"image/gif", "image/jpeg", "image/png"&#41;&#41; 
	&#41; &#123;
Falls PHP sich beschwert, ist mime_content_type() in Deinem PHP-Interpreter möglicherweise nicht eingebaut - oder ich habe mit den Klammern geschludert ;)
Ist mime_content_type() nicht eingebaut, könntest Du zumindest Spielkinder behindern:

Code: Alles auswählen

if &#40;!file_exists&#40;$dest_location&#41; 
	&& in_array&#40;strtolower&#40;$ext&#41;, Array&#40;".gif", ".jpeg", ".jpg", ".png"&#41;&#41;
	&& in_array&#40;$upfile_info&#91;'type'&#93;, Array&#40;"image/gif", "image/jpeg", "image/png"&#41;&#41; 
	&#41; &#123;
$upfile_info['type'] enthält allerdings die Dateitypangabe, die der Browser geschickt hat, und ist deshalb nicht sonderlich vertrauenswürdig. mime_content_type() prüft hingegen selbst die Datei.

Bei der Gelegenheit möchtest Du die Zeilen 6, 10 und 17 absichern:

Code: Alles auswählen

06 $file_name = str_replace&#40;Array&#40;"'", "/"&#41;, Array&#40;"", "_"&#41;, $file_name&#41;;

Code: Alles auswählen

10 move_uploaded_file&#40;$upfile_info&#91;'tmp_name'&#93;, $dest_location&#41;;

Code: Alles auswählen

17 $MSG="<b>" . htmlspecialchars&#40;$dest_location&#41; . "</b> &#40;mime&#58; " . htmlspecialchars&#40;$type&#41; . " | size&#58; " . $size . " KB&#41;";
Vor Benutzung bitte die Zeilennummern entfernen. Und jetzt bekomme ich 5 Euro von Dir :)

Punic@
PostRank 1
PostRank 1
Beiträge: 4
Registriert: 22.06.2006, 15:16

Beitrag von Punic@ » 22.06.2006, 18:25

Lol mal gucken :lol: wegen den 5 T€uros :wink: Vielen Dank für die Ausführliche erklärung :)

Anzeige von ABAKUS

von Anzeige von ABAKUS »

Content Erstellung von ABAKUS Internet Marketing
Ihre Vorteile:
  • einzigartige Texte
  • suchmaschinenoptimierte Inhalte
  • eine sinnvolle Content-Strategie
  • Beratung und Umsetzung
Jetzt anfragen: 0511 / 300325-0

haha
PostRank 9
PostRank 9
Beiträge: 1065
Registriert: 03.04.2006, 18:08
Wohnort: Bi Hamborg

Beitrag von haha » 22.06.2006, 19:09

Punic@ hat geschrieben:Lol mal gucken :lol: wegen den 5 T€uros :wink:
Was heißt hier "Teuro"? Für so eine hochqualitative Beratungsdienstleistung müsste ich eigentlich 10 Euro verlangen. Mindestens! MINDESTENS! ;)

Punic@
PostRank 1
PostRank 1
Beiträge: 4
Registriert: 22.06.2006, 15:16

Beitrag von Punic@ » 22.06.2006, 20:51

Jetzt muss ich aber schnell zahlen du gehst ja immer höher mit den Preisen :o :lol: :x

Punic@
PostRank 1
PostRank 1
Beiträge: 4
Registriert: 22.06.2006, 15:16

Beitrag von Punic@ » 18.07.2006, 21:15

OK Hat alles geklappt mit der nicht so billigen Lösung bedanke mich mal nochmal und bin happy :D

Antworten
  • Vergleichbare Themen
    Antworten
    Zugriffe
    Letzter Beitrag