Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Un Miracolo?

  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2008
    Messaggi
    143

    Un Miracolo?

    HEHE... AZZ...
    Ciao posto il codice non ci sto capendo piu una sega, sono ultra dilettante con php e dovrei far funzionare questo script:

    $result = array();

    $result['time'] = date('r');
    $result['addr'] = substr_replace(gethostbyaddr($_SERVER['REMOTE_ADDR']), '******', 0, 6);
    $result['agent'] = $_SERVER['HTTP_USER_AGENT'];

    if (count($_GET)) {
    $result['get'] = $_GET;
    }
    if (count($_POST)) {
    $result['post'] = $_POST;
    }
    if (count($_FILES)) {
    $result['files'] = $_FILES;
    }

    // we kill an old file to keep the size small
    if (file_exists('script.log') && filesize('script.log') > 102400) {
    unlink('script.log');
    }

    $log = @fopen('script.log', 'a');
    if ($log) {
    fputs($log, print_r($result, true) . "\n---\n");
    fclose($log);
    }


    // Validation

    $error = false;

    if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
    $error = 'Invalid Upload';
    }

    if (!$error && $_FILES['Filedata']['size'] > 2 * 1024 * 1024)
    {
    $error = 'Please upload only files smaller than 2Mb!';
    }

    if (!$error && !($size = @getimagesize($_FILES['Filedata']['tmp_name']) ) )
    {
    $error = 'Please upload only images, no other files are supported.';
    }

    if (!$error && !in_array($size[2], array(1, 2, 3, 7, 8) ) )
    {
    $error = 'Please upload only images of type JPEG, GIF or PNG.';
    }

    if (!$error && ($size[0] < 25) || ($size[1] < 25))
    {
    $error = 'Please upload an image bigger than 25px.';
    }

    if(move_uploaded_file($_FILES['Filedata']['tmp_name'], "/tmp/upload".basename($_FILES['file']['name'])))

    {

    $return['src'] = '/home/data/c0102214/tmp/upload' . $_FILES['Filedata']['name'];
    }

    if ($error) {

    $return = array(
    'status' => '0',
    'error' => $error
    );

    } else {

    $return = array(
    'status' => '1',
    'name' => $_FILES['Filedata']['name']
    );

    // Our processing, we get a hash value from the file
    $return['hash'] = md5_file($_FILES['Filedata']['tmp_name']);

    // ... and if available, we get image data
    $info = @getimagesize($_FILES['Filedata']['tmp_name']);

    if ($info) {
    $return['width'] = $info[0];
    $return['height'] = $info[1];
    $return['mime'] = $info['mime'];
    }

    }


    // Output

    /**
    * Again, a demo case. We can switch here, for different showcases
    * between different formats. You can also return plain data, like an URL
    * or whatever you want.
    *
    * The Content-type headers are uncommented, since Flash doesn't care for them
    * anyway. This way also the IFrame-based uploader sees the content.
    */

    if (isset($_REQUEST['response']) && $_REQUEST['response'] == 'xml') {
    // header('Content-type: text/xml');

    // Really dirty, use DOM and CDATA section!
    echo '<response>';
    foreach ($return as $key => $value) {
    echo "<$key><![CDATA[$value]]></$key>";
    }
    echo '</response>';
    } else {
    // header('Content-type: application/json');

    echo json_encode($return);
    }

    ?>

    praticamente serve a fare upload con swf, teoricamente mi dovrebbe creare un cartella in /temp/ con un nome random che gli assegna lui e in questa caricarmi il file.

    Ora mi sono perso il milgior risultato che ho raggiunto è far caricare il file in /temp/upload

    mentre con le altre prove ricevo quasis empre lo stesso errore l'ultimo è:

    Warning: md5_file(/tmp/phpHNJuby) [function.md5-file]: failed to open stream: No such file or directory in /home/data/c0102214/public_html/dir/sezioni/galleria_foto/foto/server/script.php on line 118
    {"status":"1","name":"Image.jpg","hash":false}

    c'è un file .log ce richiede 777 mentre per il file php non sono ancora riuscito a capire, lasciando default come permessi almeno esegue, se gli do permessi aggiuntivi (errore 500 e upload fallito).

    We che dire se qualcuno mi vuole dare uan mano, questo script mi servirebbe veramente, ne ho provati diversi ma questo il migliore per certi versi.
    Il fatto è che se non mi crea la cartella con il file, se u altro utente carica una foto con lo stesso nome la sovrascrive e cmq diventerebbe un casino gestire le foto.

    GRAZIE GRAZIE GRAZIE!!!

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2008
    Messaggi
    143

    semplifichiamo

    Lo script in origine ha questo codice:

    if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
    $error = 'Invalid Upload';
    }

    cosi in automatico dovrebbe creare la cartella temporanea con il file dentro, fatto sta che facendo l'upload mi da ok ma non esiste ne il file ne la cartella.

    io ho modificato cosi:

    $upload_directory = $_SERVER[DOCUMENT_ROOT] ."/home/data/c0102214/tmp/upload/";

    if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
    $error = 'Caricamento non riuscito';
    }

    cosi carica i file ma non crea una cartella

    un aiuto?

  3. #3
    Utente di HTML.it L'avatar di nicola75ss
    Registrato dal
    Nov 2004
    Messaggi
    12,922
    Leggi il regolamento e riapri la discussione con un titolo a norma.

    Usa i tag [php ] e [/php ] senza lo spazio finale per racchiudere il tuo codice e renderne più comprensibile la lettura agli altri utenti.

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.