Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    upload immagini da flash a db

    salve ragazzi e buon natale/fine anno a tutti...qualcuno gentilmente pou postarmi uno script per uplodare da flash un immagine in un db mysql??

    ho trovato questo codice: (per flash 8)

    System.security.allowDomain("http://localhost/");
    import flash.net.FileReference;
    // The listener object listens for FileReference events.
    var listener:Object = new Object();

    // When the user selects a file, the onSelect() method is called, and
    // passed a reference to the FileReference object.
    listener.onSelect = function(selectedFile:FileReference):Void {
    //clean statusArea and details area
    statusArea.text = details.text = ""
    // Flash is attempting to upload the image.
    statusArea.text += "Attempting to upload " + selectedFile.name + "\n";
    // Upload the file to the PHP script on the server.
    selectedFile.upload("upload.php");
    };

    // the file is starting to upload.
    listener.onOpen = function(selectedFile:FileReference):Void {
    statusArea.text += "Uploading " + selectedFile.name + "\n";
    };
    //Possible file upload errors
    listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
    imagePane.contentPath = "error";
    imagePane.content.errorMSG.text = "HTTPError number: "+httpError +"\nFile: "+ file.name;
    }

    listener.onIOError = function(file:FileReference):Void {
    imagePane.contentPath = "error";
    imagePane.content.errorMSG.text = "IOError: "+ file.name;
    }

    listener.onSecurityError = function(file:FileReference, errorString:String):Void {
    imagePane.contentPath = "error";
    imagePane.content.errorMSG.text = "SecurityError: "+SecurityError+"\nFile: "+ file.name;
    }

    // the file has uploaded
    listener.onComplete = function(selectedFile:FileReference):Void {
    // Notify the user that Flash is starting to download the image.
    statusArea.text += "Upload finished.\nNow downloading " + selectedFile.name + " to player\n";
    //Show file details
    details.text = ""
    for(i in selectedFile) details.text +=""+i+": "+selectedFile[i]+"\n"
    // Call the custom downloadImage() function.
    downloadImage(selectedFile.name);
    };

    var imageFile:FileReference = new FileReference();
    imageFile.addListener(listener);

    uploadBtn.onPress = uploadImage;
    imagePane.addEventListener("complete", imageDownloaded);

    // Call the uploadImage() function, opens a file browser dialog.
    function uploadImage(event:Object):Void {
    imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png"}]);
    }

    // If the image does not download, the event object's total property
    // will equal -1. In that case, display am error message
    function imageDownloaded(event:Object):Void {
    if(event.total == -1) {
    imagePane.contentPath = "error";
    }
    }

    // show uploaded image in scrollPane
    function downloadImage(file:Object):Void {
    imagePane.contentPath = "./files/" + file;
    }

    stop()


    questo il file in php :

    <?php
    //create the directory if doesn't exists (should have write permissons)
    if(!is_dir("./files")) mkdir("./files", 0755);
    //move the uploaded file
    move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_FILES['Filedata']['name']);
    chmod("./files/".$_FILES['Filedata']['name'], 0777);
    ?>


    e funziona perfettamente per creare una cartella io invece vorrei inserire l'immagine in un database mysql

    questo script php lo fa :

    <?php

    if(!isset($_POST)) $_POST = $HTTP_POST_VARS;
    $self = isset($_SERVER) ? $_SERVER["PHP_SELF"] : $HTTP_SERVER_VARS["PHP_SELF"];

    if($_POST["invia"]) {

    // CONNESSIONE AL MYSQL
    @mysql_connect("localhost", "root", "qqqwww") or die("Connessione fallita !");

    // SELEZIONE DATABASE
    @mysql_select_db("FileBinari") or die("Selezione Database fallita !");

    // MEMORIZZIAMO NELLA VARIABILE $data IL CONTENUTO DEL FILE
    $data = addslashes(fread(fopen($_FILES["file_binario"]["tmp_name"], "rb"), $_FILES["file_binario"]["size"]));

    // ESEGUIAMO LA QUERY DI INSERIMENTO
    $result = @mysql_query("INSERT INTO file_binari (Descrizione, DatiBinari, Nome, Size, Type)
    VALUES ('" . $_POST["Descrizione"] . "','$data','" . $_FILES["file_binario"]["name"] . "',
    '" . $_FILES["file_binario"]["size"] . "','" . $_FILES["file_binario"]["type"] . "')")
    or die("Query di inserimento fallita !");

    // ESITO POSITIVO
    echo "Il file " . basename($_FILES["file_binario"]["name"]) . " è stato correttamente inserito nel Database.";

    // CHIUDIAMO LA CONNESSIONE A MYSQL
    @mysql_close();

    ?>


    qualcuno sa dirmi come cambiare lo script in flash per adattarlo a questo script php? (sempre se possibile)??? ringrazio anticipatamente...

    se qualcuno invece avesse qualcosa di gia sperimentato e funzionante lo prego di postarmi il codice di entrambi gli script grazie

  2. #2
    risolto ...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.