Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Moin zusammen!

Ich muss einen Dateiupload erstellen wo die Dateigröße und der Typ vor dem Upload überprüft wird.

Ich habe schon etwas länger gegoggelt und keinen Ansatz gefunden nur über Active X wenn möglich soll das aber per Javascript gelört werden.

Habe auch eine Variante gefunden wo man bei <input type=file >

noch accept und maxlenght eingibt aber so ganz haut das auch nicht hin. Selbst auf selfhtml wird bei dieser variante gesagt das das nicht so ganz hin haut und nicht immer funtkioniert.

Wenn jemand eine Idee hat möge er sie posten

Ich habe dir da mal was zusammenkopiert.


$user_avatar_name = ( !empty($HTTP_POST_FILES['avatar']['name']) ) ? $HTTP_POST_FILES['avatar']['name'] : '';
$user_avatar_loc = ( $HTTP_POST_FILES['avatar']['tmp_name'] != "none") ? $HTTP_POST_FILES['avatar']['tmp_name'] : '';
$user_avatar_size = ( !empty($HTTP_POST_FILES['avatar']['size']) ) ? $HTTP_POST_FILES['avatar']['size'] : 0;
$user_avatar_filetype = ( !empty($HTTP_POST_FILES['avatar']['type']) ) ? $HTTP_POST_FILES['avatar']['type'] : '';

if( file_exists($user_avatar_loc) && ereg(".jpg$|.gif$|.png$", $user_avatar_name) )
{
if( $user_avatar_size <= $forum_config['avatar_groesse'] && $user_avatar_size > 0)
{
$error_type = false;

//
// Opera appends the image name after the type, not big, not clever!
//
preg_match("'image\/[x\-]*([a-z]+)'", $user_avatar_filetype, $user_avatar_filetype);
$user_avatar_filetype = $user_avatar_filetype[1];

switch( $user_avatar_filetype )
{
case "jpeg":
case "pjpeg":
case "jpg":
$imgtype = '.jpg';
break;
case "gif":
$imgtype = '.gif';
break;
case "png":
$imgtype = '.png';
break;
default:
$error = true;
$error_msg = (!empty($error_msg)) ? $error_msg . "<br />" . "Der Avatar muss im GIF-, JPG- oder PNG-Format sein." : "Der Avatar muss im GIF-, JPG- oder PNG-Format sein.";
break;
}

if( !$error )
{
list($width, $height) = @getimagesize($user_avatar_loc);

if( $width <= $forum_config['avatar_breite'] && $height <= $forum_config['avatar_hoehe'] )
{
$user_id = $_SESSION['session_userid'];

$avatar_filename = $user_id . $imgtype;

if( $_POST[avatar_type] == "1" && $_POST[avatar_bild] != "" )
{
if( @file_exists("./pictures/avatar/images/" . $_POST[avatar_bild]) )
{
@unlink("./pictures/avatar/images/". $_POST[avatar_bild]);
}
}
@copy($user_avatar_loc, "./pictures/avatar/images/".$avatar_filename);

//Dateiname und Type in Datenbank speichern

//...
}
else
{
$l_avatar_size = sprintf("Der Avatar muss weniger als " . $forum_config['avatar_breite'] . " Pixel breit und " . $forum_config['avatar_hoehe'] . " Pixel hoch sein." , $forum_config['avatar_breite'], $forum_config['avatar_hoehe']);

$error = true;
$error_msg = ( !empty($error_msg) ) ? $error_msg . "<br />" . $l_avatar_size : $l_avatar_size;
}
}
}
else
{
$l_avatar_size = sprintf("Die Dateigrösse muss kleiner als %d kB sein.", round($forum_config['avatar_groesse'] / 1024));

$error = true;
$error_msg = ( !empty($error_msg) ) ? $error_msg . "<br />" . $l_avatar_size : $l_avatar_size;
}
}
else
{
$error = true;
$error_msg = ( !empty($error_msg) ) ? $error_msg . "<br />" . "Der Avatar muss im GIF-, JPG- oder PNG-Format sein." : "Der Avatar muss im GIF-, JPG- oder PNG-Format sein.";
}
[/php]

Frank

Aber ist es bei dem Script nicht so das die Datei bereits hochgeladen wurde?

Leider habe ich auch nicht die Möglichkeit PHP Code einzubinden mit bleibt nur Javascript

ich denke mal er möchte vor dem Hochladen erst die Grösse überprüfen.

wobei ich jetzt aber nichts wüsste was man da machen kann...

ich muss die überprüfung für ein bestehende System schreiben bzw einbauen.

Der Upload funktioniert über das System nur dort ist keine Funktion eingebaut um die Datei größe bzw Art zu überprüfen. Das Problem ist das es halt vor dem Upload passieren muss, ich habe auch schon gegoogelt aber zu 99% bin ich davon überzeugt das es nicht geht. Dennoch muss ich irgendwie eine Lösung finden, jedoch bleibt mir nur Javascript.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.