Pagina 1 di 4 1 2 3 ... ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 32
  1. #1

    File sovrascritti in upload

    Questo script effettua l upload di un immagine, però quando uppo un img con lo stesso nome di una gia contenuta mi sovrascrive quella gia contenuta, qualcuno può aiutarmi a risolvere questo problema?non sono pratico di php qualcuno può modificare il codice per far si che non si sorascrivino più le immagini?

    Codice PHP:
    <?php ini_set("memory_limit""200000000"); // for large images so that we do not get "Allowed memory exhausted"?> <?php // upload the file if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) {          // file needs to be jpg,gif,bmp,x-png and 4 MB max     if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 4000000))     {                     // some settings         $max_upload_width = 2592;         $max_upload_height = 1944;                    // if user chosed properly then scale down the image according to user preferances         if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){             $max_upload_width = $_REQUEST['max_width_box'];         }             if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){             $max_upload_height = $_REQUEST['max_height_box'];         }                       // if uploaded image was JPG/JPEG         if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){                 $image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]);         }                 // if uploaded image was GIF         if($_FILES["image_upload_box"]["type"] == "image/gif"){                 $image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);         }             // BMP doesn't seem to be supported so remove it form above image type test (reject bmps)             // if uploaded image was BMP         if($_FILES["image_upload_box"]["type"] == "image/bmp"){                 $image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]);         }                     // if uploaded image was PNG         if($_FILES["image_upload_box"]["type"] == "image/x-png"){             $image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]);         }                   $remote_file = "image_files/".$_FILES["image_upload_box"]["name"];         imagejpeg($image_source,$remote_file,100);         chmod($remote_file,0644);                    // get width and height of original image         list($image_width, $image_height) = getimagesize($remote_file);              if($image_width>$max_upload_width || $image_height >$max_upload_height){             $proportions = $image_width/$image_height;                          if($image_width>$image_height){                 $new_width = $max_upload_width;                 $new_height = round($max_upload_width/$proportions);             }                     else{                 $new_height = $max_upload_height;                 $new_width = round($max_upload_height*$proportions);             }                                               $new_image = imagecreatetruecolor($new_width , $new_height);             $image_source = imagecreatefromjpeg($remote_file);                          imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);             imagejpeg($new_image,$remote_file,100);                          imagedestroy($new_image);         }                  imagedestroy($image_source);                           header("Location: submit.php?upload_message=Immagine caricata con successo&upload_message_type=success&show_image=".$_FILES["image_upload_box"]["name"]);         exit;     }     else{         header("Location: submit.php?upload_message=Assicurati che l'immagine abbia estenzione jpg, gif o png e che la sua grandezza sia minore o uguale a 4MB&upload_message_type=error");         exit;     } } ?>
    dddd

  2. #2
    Per favore posta di nuovo il codice in modo che sia più leggibie (es. non tutto su una unica riga).

  3. #3
    si, se ci riesco.

    <?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?>
    <?php
    // upload the file
    if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) {

    // file needs to be jpg,gif,bmp,png and 4 MB max
    if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/png") && ($_FILES["image_upload_box"]["size"] < 4000000))
    {


    // some settings
    $max_upload_width = 2592;
    $max_upload_height = 1944;

    // if user chosed properly then scale down the image according to user preferances
    if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){
    $max_upload_width = $_REQUEST['max_width_box'];
    }
    if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){
    $max_upload_height = $_REQUEST['max_height_box'];
    }


    // if uploaded image was JPG/JPEG
    if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){
    $image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]);
    }
    // if uploaded image was GIF
    if($_FILES["image_upload_box"]["type"] == "image/gif"){
    $image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);
    }
    // BMP doesn't seem to be supported so remove it form above image type test (reject bmps)
    // if uploaded image was BMP
    if($_FILES["image_upload_box"]["type"] == "image/bmp"){
    $image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]);
    }
    // if uploaded image was PNG
    if($_FILES["image_upload_box"]["type"] == "image/png"){
    $image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]);
    }


    $remote_file = "image_files/".$_FILES["image_upload_box"]["name"];
    imagejpeg($image_source,$remote_file,100);
    chmod($remote_file,0644);



    // get width and height of original image
    list($image_width, $image_height) = getimagesize($remote_file);

    if($image_width>$max_upload_width || $image_height >$max_upload_height){
    $proportions = $image_width/$image_height;

    if($image_width>$image_height){
    $new_width = $max_upload_width;
    $new_height = round($max_upload_width/$proportions);
    }
    else{
    $new_height = $max_upload_height;
    $new_width = round($max_upload_height*$proportions);
    }


    $new_image = imagecreatetruecolor($new_width , $new_height);
    $image_source = imagecreatefromjpeg($remote_file);

    imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
    imagejpeg($new_image,$remote_file,100);

    imagedestroy($new_image);
    }

    imagedestroy($image_source);


    header("Location: submit.php?upload_message=Immagine caricata con successo&upload_message_type=success&show_image=". $_FILES["image_upload_box"]["name"]);
    exit;
    }
    else{
    header("Location: submit.php?upload_message=Assicurati che l'immagine abbia estenzione jpg, gif o png e che la sua grandezza sia minore o uguale a 4MB&upload_message_type=error");
    exit;
    }
    }
    ?>
    dddd

  4. #4
    Prova a sostituire la riga:

    Codice PHP:
    $remote_file "image_files/".$_FILES["image_upload_box"]["name"]; 
    con:

    Codice PHP:
    $remote_file "image_files/" $_FILES["image_upload_box"]["name"];
    $ext substr($remote_filestrrpos($remote_file'.'));
    $remote_filename substr($remote_file0, -strlen($ext));
    $i 1;
    while (
    file_exists($remote_file)) {
        
    $remote_file $remote_filename $i $ext;
        
    $i++;


  5. #5
    fatto, non cambia niente.
    dddd

  6. #6
    Scusa, mi è sfuggito un ! utilizzato per i test. Prova ora:

    Codice PHP:
    $remote_file "image_files/" $_FILES["image_upload_box"]["name"];
    $ext substr($remote_filestrrpos($remote_file'.'));
    $remote_filename substr($remote_file0, -strlen($ext));
    $i 1;
    while (
    file_exists($remote_file)) {
        
    $remote_file $remote_filename $i $ext;
        
    $i++;


  7. #7
    però poi qudo voglio far apparire l immagine sotto appena dopo aver uppato prima scrivevo [img]image_files/<?php echo $_REQUEST['show_image'];?>[/img] adesso che debbo scrivere pe rnon far comparire quella uppata prima con lo stesso nome?
    dddd

  8. #8
    Invece di:

    Codice PHP:
    header("Location: submit.php?upload_message=Immagine caricata con successo&upload_message_type=success&show_image=".$_FILES["image_upload_box"]["name"]); 
    Scrivi:

    Codice PHP:
    header("Location: submit.php?upload_message=Immagine caricata con successo&upload_message_type=success&show_image=" urlencode(basename($remote_file)); 

  9. #9
    non va, nella pagina per richiamare l immagine uso
    Codice PHP:
    <?php echo $_REQUEST['show_image'];?>
    (e prima metto io l indirizzo del sito) adesso come debbo fare?
    dddd

  10. #10

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 © 2024 vBulletin Solutions, Inc. All rights reserved.