Ankündigung

Einklappen
Keine Ankündigung bisher.

Image Link in zwischenablage kopieren (nach image upload)

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Image Link in zwischenablage kopieren (nach image upload)

    Hallo,

    ich habe ein php skript mit dem ich bilder auf meinen Server laden kann (für eine kleines intranet forum). Nach dem hochladen hätte ich aber gerne die linkadresse in die zwischenablage kopiert damit ich die diese gleich in ein [img][/img] kopieren kann.

    könnte mir da bitte jemand helfen /einen tipp geben?

    mein skript schaut so aus:

    upload.form.php

    PHP-Code:
    <?php

    // filename: upload.form.php

    // first let's set some variables

    // make a note of the current working directory relative to root.
    $directory_self str_replace(basename($_SERVER['PHP_SELF']), ''$_SERVER['PHP_SELF']);

    // make a note of the location of the upload handler
    $uploadHandler 'http://' $_SERVER['HTTP_HOST'] . $directory_self 'upload.processor.php';

    // set a max file size for the html upload form
    $max_file_size 3072000// size in bytes

    // now echo the html page
    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en">
        <head>
            <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
        
            <link rel="stylesheet" type="text/css" href="stylesheet.css">
            
            <title>Upload form</title>
        
        </head>
        
        <body>
        
        <form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">
        
            <h1>
                Bilder für das GIS-Wiki-Forum hochladen
            </h1>
            
            <p>
                <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
            </p>
            
            <p>
                <label for="file">Bild_auswählen (max. 3MB):</label>
                <input id="file" type="file" name="file">
            </p>
                    
            <p>
                <label for="submit">Hochladen ...</label>
                <input id="submit" type="submit" name="submit" value="Bild Hochladen!">
            </p>
        
        </form>
        
        
        </body>

    </html>

    upload.processor.php

    PHP-Code:
    <?php  

    // filename: upload.processor.php

    // first let's set some variables

    // make a note of the current working directory, relative to root.
    $directory_self str_replace(basename($_SERVER['PHP_SELF']), ''$_SERVER['PHP_SELF']);

    // make a note of the directory that will recieve the uploaded files
    $uploadsDirectory $_SERVER['DOCUMENT_ROOT'] . $directory_self 'uploaded_files/';

    // make a note of the location of the upload form in case we need it
    $uploadForm 'http://' $_SERVER['HTTP_HOST'] . $directory_self 'upload.form.php';

    // make a note of the location of the success page
    $uploadSuccess 'http://' $_SERVER['HTTP_HOST'] . $directory_self 'upload.success.php';

    // name of the fieldname used for the file in the HTML form
    $fieldname 'file';



    // Now let's deal with the upload

    // possible PHP upload errors
    $errors = array(=> 'php.ini max file size exceeded'
                    
    => 'html form max file size exceeded'
                    
    => 'file upload was only partial'
                    
    => 'no file was attached');

    // check the upload form was actually submitted else print form
    isset($_POST['submit'])
        or 
    error('the upload form is neaded'$uploadForm);

    // check for standard uploading errors
    ($_FILES[$fieldname]['error'] == 0)
        or 
    error($errors[$_FILES[$fieldname]['error']], $uploadForm);
        
    // check that the file we are working on really was an HTTP upload
    @is_uploaded_file($_FILES[$fieldname]['tmp_name'])
        or 
    error('not an HTTP upload'$uploadForm);
        
    // validation... since this is an image upload script we 
    // should run a check to make sure the upload is an image
    @getimagesize($_FILES[$fieldname]['tmp_name'])
        or 
    error('only image uploads are allowed'$uploadForm);
        
    // make a unique filename for the uploaded file and check it is 
    // not taken... if it is keep trying until we find a vacant one
    $now time();
    while(
    file_exists($uploadFilename $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
    {
        
    $now++;
    }

    // now let's move the file to its final and allocate it with the new filename
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
        or 
    error('receiving directory insuffiecient permission'$uploadForm);
        
    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to the success page.
    header('Location: ' $uploadSuccess);

    // make an error handler which will be used if the upload fails
    function error($error$location$seconds 5)
    {
        
    header("Refresh: $seconds; URL=\"$location\"");
        echo 
    '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
        
    '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
        
    '<html lang="en">'."\n".
        
    '    <head>'."\n".
        
    '        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
        
    '        <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
        
    '    <title>Upload error</title>'."\n\n".
        
    '    </head>'."\n\n".
        
    '    <body>'."\n\n".
        
    '    <div id="Upload">'."\n\n".
        
    '        <h1>Upload failure</h1>'."\n\n".
        
    '        <p>An error has occured: '."\n\n".
        
    '        <span class="red">' $error '...</span>'."\n\n".
        
    '         The upload form is reloading</p>'."\n\n".
        
    '     </div>'."\n\n".
        
    '</html>';
        exit;
    // end error handler

    ?>
    upload.success.php

    PHP-Code:
    <?php

    // filename: upload.success.php

    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en">
        <head>
            <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
            
            <link rel="stylesheet" type="text/css" href="stylesheet.css">
            
            <title>Successful upload</title>
        
        </head>
        
        <body>
        
            <div id="Upload">
                <h1>File upload</h1>
                <p>Congratulations! Your file upload was successful</p>
                <a href="http://172.22.5.104/DokuWiki/forum/image/uploader/uploaded_files/" target="LINKS">Hochgeladenes Bild suchen, link kopieren und mit [img]xxxx[/img] ins GIS-Wiki-Forum einfügen</a>

            </div>
        
        </body>

    </html>

  • #2
    Wie wäre es mit Sessions um einen Wert zwischen zu speichern?

    Wolf29
    while (!asleep()) sheep++;

    Unterschätze nie jemanden der einen Schritt zurück geht! Er könnte Anlauf nehmen.

    Kommentar


    • #3
      klingt gut, aber da ich von php nur wenig ahnung habe, könntest du mir da ein beispiel geben, wie das aussieht?

      Kommentar


      • #4
        Oha, mit nur wenig Ahnung in einem fertigen Skript rumbasteln ist kritisch. Wichtiger wäre es da vorerst Grundlagen zu lernen! Zu Sessions findest Du hier eine Referenz:

        PHP: session_start - Manual

        z.B.

        PHP-Code:
        session_start();

        $_SESSION['meinVariablenname'] = $variabledieichUebergebe
        Wolf29
        while (!asleep()) sheep++;

        Unterschätze nie jemanden der einen Schritt zurück geht! Er könnte Anlauf nehmen.

        Kommentar


        • #5
          ok, danke.... ich werde mich mal einlesen

          Kommentar


          • #6
            Zitat von dior Beitrag anzeigen
            Nach dem hochladen hätte ich aber gerne die linkadresse in die zwischenablage kopiert damit ich die diese gleich in ein [img][/img] kopieren kann.

            könnte mir da bitte jemand helfen /einen tipp geben?
            Tipp: Lass' es bleiben.

            Auf die Zwischenablage hast du nur in bestimmten Browsern unter bestimmten Bedingungen überhaupt Zugriff [1] - es wird also bei einem großen Teil der Nutzer sowieso nicht funktionieren.

            Gib die Adresse im HTML-Dokument aus, der Benutzer kann sie sich von dort kopieren. Wenn du gleich [img][/img] drumherum setzen willst, um die Nutzung in einer bestimmten Applikation zu vereinfachen, dann mach das an der Stelle.


            [1] Und wenn, dann nur per JavaScript. Das wäre also nicht mal ein PHP-Thema.
            [SIZE="1"]RGB is totally confusing - I mean, at least #C0FFEE should be brown, right?[/SIZE]

            Kommentar


            • #7
              @ChrisB

              deine Idee gefällt mir sehr gut, nur wie bekomme ich den link (den ich ja kenne) + den namen des bildes mit der "fortlaufenden nummer" als ergebnis in das Success php file (als link/text) zum kopieren?

              Kommentar


              • #8
                Da kommt dann bspw. das ins Spiel, was wolf29 schon sagte - Sessions wären eine Möglichkeit.
                Die Übergabe als URL-Parameter in der Adresse, auf die umgeleitet wird, wäre eine weitere Möglichkeit (dabei aber URL-gerechte Kodierung nicht vergessen).
                [SIZE="1"]RGB is totally confusing - I mean, at least #C0FFEE should be brown, right?[/SIZE]

                Kommentar

                Lädt...
                X