Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Problema con immagini

  1. #1

    Problema con immagini

    Buongiorno, intanto vi dico subito che sono nuovo sia del forum che di PHP .
    Il mio problema è questo.
    Sgto provando a ridimensionare un'immagine con quesro script.

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

    <!--
    NOTE: This code has been rewritten and might be slightly different than the code
    from the video. Provided with additional comments to clarify the actions.
    -->

    <head>


    <title>Image Uploading!</title>

    </head>
    <body>

    <?php

    // Check for the POST
    if( !isset( $_POST['p'] ) ){ $_POST['p']=0; }

    if( $_POST['p'] == 1 ){
    include( 'includes/uploadimage.php' );
    }else{
    include( 'includes/uploadform.php' );
    }

    ?>

    </body>

    </html>

    Che richiama altri 2 file nella cartella includes.
    L'upload sembra lo fa ma quando arriva al 100% mi daq questo errore.

    Warning: imagejpeg(): Unable to open 'uploads/thumb_8735316fb2d0716063b483964a9b4e27.jpg' for writing: No such file or directory in /web/htdocs/www.vendoecerco.it/home/includes/uploadimage.php on line 104 Warning: move_uploaded_file(uploads/8735316fb2d0716063b483964a9b4e27.jpg): failed to open stream: No such file or directory in /web/htdocs/www.vendoecerco.it/home/includes/uploadimage.php on line 131 Warning: move_uploaded_file(): Unable to move '/tmp/php4m4WsV' to 'uploads/8735316fb2d0716063b483964a9b4e27.jpg' in /web/htdocs/www.vendoecerco.it/home/includes/uploadimage.php on line 131 You've just uploaded a new picture. This is the given data!

    Name: 8735316fb2d0716063b483964a9b4e27.jpg
    Width: 1632
    Height: 1224

    Thumbnail:


    Cosa mi consigliate di fare???

    Ho gia rispristinato i permessi.
    non ne vengo a capo, immagino che per voi sia una passeggiata.
    HELPPP

  2. #2
    Utente di HTML.it L'avatar di jcsnake
    Registrato dal
    Jun 2010
    Messaggi
    629
    Ciao, come da warning

    No such file or directory in /web/htdocs/www.vendoecerco.it/home/includes/uploadimage.php on line 104

    il problema è della pagina uploadimage.php. Posta il codice così da capire dov'è l'errore.

  3. #3
    <?php

    // File Variables
    $name= $_FILES['image']['name'];
    $temp= $_FILES['image']['tmp_name'];
    $type= $_FILES['image']['type'];
    $size= $_FILES['image']['size'];
    $size2= getimagesize( $temp );
    $width= $size2[0];
    $height= $size2[1];
    $upload= md5( rand( 0, 1000 ) . rand( 0, 1000 ) . rand( 0, 1000 ) . rand( 0, 1000 ) );

    // Restrictions for uploading
    $maxwidth= 2920;
    $maxheight= 2080;
    $allowed= array( 'image/jpeg', 'image/png', 'image/gif' );

    // Recognizing the extension
    switch( $type ){

    // Image/Jpeg
    case 'image/jpeg':
    $ext= '.jpg';
    break;

    // Image/png
    case 'image/png':
    $ext= '.png';
    break;

    // Image/gif
    case 'image/gif':
    $ext= '.gif';
    break;

    }

    // Upload Variables
    $path= 'uploads/' . $upload . $ext;
    $thumb_path= 'uploads/thumb_' . $upload . $ext;
    $data= "You've just uploaded a new picture. This is the given data!

    Name: " . $upload . $ext . "
    Width: " . $width . "
    Height: " . $height . "

    Thumbnail:
    <img src=\"uploads/thumb_" . $upload . $ext . "\" alt=\"Thumbnail\" />
    Original:
    <img src=\"uploads/" . $upload . $ext . "\" alt=\"Original\" />";

    // Check for the Image post.
    if( $_POST ){

    // Got into the POST check.

    if( $_FILES ){

    // Checking if the extension is allowed.
    if( in_array( $type, $allowed ) ){

    // Checking if the resolution is FULLHD or under this resolution.
    if( $width <= $maxwidth && $height <= $maxheight ){

    // Checking if the image is 5MB or less.
    if( $size <= 15242880 ){

    // Check the shape of the image.
    if( $width == $height ){ $shape=1; }
    if( $width < $height ){ $shape=2; }
    if( $width > $height ){ $shape=3; }

    // Ajusting the resize script on shape.
    switch( $shape ){

    // Code to resize a square image.
    case 1:

    $newwidth= 100;
    $newheight= 100;

    break;

    // Code to resize a tall image.
    case 2:

    $newwidth= 100;
    $ratio= $newwidth / $width;
    $newheight= round( $height * $ratio );

    break;

    // Code to resize a wide image.
    case 3:

    $newheight= 100;
    $ratio= $newheight / $height;
    $newwidth= round( $width * $ratio );

    break;

    }

    // Resizing according to extension.
    switch( $type ){

    // Image/Jpeg
    case 'image/jpeg':

    $img= imagecreatefromjpeg( $temp );
    $thumb= imagecreatetruecolor( $newwidth, $newheight );
    imagecopyresized( $thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );
    imagejpeg( $thumb, $thumb_path );

    break;

    // Image/png
    case 'image/png':

    $img= imagecreatefrompng( $temp );
    $thumb= imagecreatetruecolor( $newwidth, $newheight );
    imagecopyresized( $thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );
    imagepng( $thumb, $thumb_path );

    break;

    // Image/gif
    case 'image/gif':

    $img= imagecreatefromgif( $temp );
    $thumb= imagecreatetruecolor( $newwidth, $newheight );
    imagecopyresized( $thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );
    imagegif( $thumb, $thumb_path );

    break;

    }

    // Move the original file aswell.
    move_uploaded_file( $temp, $path );

    // Putting out the data.
    echo $data;

    }else{ die( "Your picture did not pass the size restrictions filter." ); }

    }else{ die( "Your picture did not pass the resolution restrictions filter." ); }

    }else{ die( "Your picture did not pass the extension restrictions filter." ); }

    }

    }

    ?>

  4. #4
    il modo in cui esegui l'upload e il resize delle img è molto approssimativo e poco "controllato".

    Studiati questo script/tutorial:
    http://net.tutsplus.com/tutorials/ph...easy-with-php/
    oppure:
    http://www.verot.net/php_class_upload.htm

    giusto per citarne alcuni...

    -----------------
    Da uno sguardo superficiale dello script sono quasi certo che l'errore dipenda da un errata indicazione del path in cui salvare il file specificato in questi righi:
    Codice PHP:
    $path'uploads/' $upload $ext;
    $thumb_path'uploads/thumb_' $upload $ext
    http://www.miniscript.it
    Se ti sono stato di aiuto in qualche modo in questo forum iscriviti alla fan page di Miniscript - il mio blog di programmazione web.

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.