Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Pdf

  1. #1
    Utente di HTML.it L'avatar di remixe
    Registrato dal
    Aug 2004
    Messaggi
    645

    Pdf

    ciao a tutti,
    ho un form e del codice con cui carico un immagine sul database,il
    tutto funziona bene.

    Ora..ho provato con lo stesso identico sistema a caricare invece di un immagine un file .pdf
    soltanto che la pagina mi risponde che non è il tipo di file corretto in quanto non è ne un jpg ne un gif ne un png.
    Come posso modificare questo script per fargli caricare questo famigerato pdf?

    Allego il codice che sto utilizzando quì sotto.

    grazie in anticipo


    il primo file:

    <html>
    <head>
    <title>Upload your pic to our site!</title>
    </head>
    <body>

    <form name="form1" method="post" action="check_image.php"
    enctype="multipart/form-data">

    <table border="0" cellpadding="5">
    <tr>
    <td>Image Title or Caption

    Example: You talkin' to me?</td>
    <td><input name="image_caption" type="text" id="item_caption" size="55"
    maxlength="255"></td>
    </tr>
    <tr>
    <td>Your Username</td>
    <td><input name="image_username" type="text" id="image_username" size="15"
    maxlength="255"></td>
    </tr>
    <td>Upload Image:</td>
    <td><input name="image_filename" type="file" id="image_filename"></td>
    </tr>
    </table>


    Acceptable image formats include: GIF, JPG/JPEG, and PNG.
    <p align="center"><input type="submit" name="Submit" value="Submit">

    <input type="reset" name="Submit2" value="Clear Form">
    </p>
    </form>
    </body>
    </html>


    il secondo:

    <?php
    //connect to the database
    $link = mysql_connect("localhost", "", "")
    or die("Could not connect: " . mysql_error());
    mysql_select_db("", $link)
    or die (mysql_error());

    //make variables available
    $image_caption = $_POST['image_caption'];
    $image_username = $_POST['image_username'];
    $image_tempname = $_FILES['image_filename']['name'];
    $today = date("Y-m-d");

    //upload image and check for image type
    //make sure to change your path to match your images directory
    $ImageDir ='/home/httpd/vhosts/allmediaservice.it/httpdocs/imup/uploads/';
    $ImageName = $ImageDir . $image_tempname;

    if (move_uploaded_file($_FILES['image_filename']['tmp_name'],
    $ImageName)) {

    //get info about the image being uploaded
    list($width, $height, $type, $attr) = getimagesize($ImageName);

    switch ($type) {
    case 1:
    $ext = ".pdf";
    break;
    case 2:
    $ext = ".jpg";
    break;
    case 3:
    $ext = ".png";
    break;
    default:
    echo "Sorry, but the file you uploaded was not a GIF, JPG, or " .
    "PNG file.
    ";
    echo "Please hit your browser's 'back' button and try again.";
    }

    //insert info into image table

    $insert = "INSERT INTO images
    (image_caption, image_username, image_date)
    VALUES
    ('$image_caption', '$image_username', '$today')";
    $insertresults = mysql_query($insert)
    or die(mysql_error());

    $lastpicid = mysql_insert_id();

    $newfilename = $ImageDir . $lastpicid . $ext;

    rename($ImageName, $newfilename);

    }

    ?>

    <html>
    <head>
    <title>Here is your pic!</title>
    </head>
    <body>
    <h1>So how does it feel to be famous?</h1>




    Here is the picture you just uploaded to our servers:</p>
    [img]images/<?php echo $lastpicid . $ext; ?>[/img]
    <?php echo $image_name; ?>

    This image is a <?php echo $ext; ?> image.

    It is <?php echo $width; ?> pixels wide
    and <?php echo $height; ?> pixels high.

    It was uploaded on <?php echo $today; ?>.
    </body>
    </html>
    nessuno

  2. #2
    Utente di HTML.it L'avatar di remixe
    Registrato dal
    Aug 2004
    Messaggi
    645

    re

    mi sembra di capire che i pdf allo stato attuale abbiano dei problemi con il php
    nessuno

  3. #3
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120

    Re: re

    Originariamente inviato da remixe
    mi sembra di capire che i pdf allo stato attuale abbiano dei problemi con il php
    Più che i pdf mi sa che sei tu ad avere problemi col php...

    Se chiami una funzione fatta per le immagini (getimagesize) non è che puoi pretendere che riconosca un file pdf.
    Quindi o eviti di chiamarla, oppure prevedi che non riconosca il file e ti comporti di conseguenza. Come fare esattamente dipende da quanti e quali tipi di file prevedi di dover/poter caricare

  4. #4
    Utente di HTML.it L'avatar di remixe
    Registrato dal
    Aug 2004
    Messaggi
    645

    re

    ciao Luca
    infatti lo script che ho postato è perfetto per uplodare le immagini
    e funziona.
    Come ti dicevo ora voglio trasformarlo affinchè invece delle immagini carichi i pdf
    soltanto che nonostante stia cercando materiale specifico dei pdf appunto
    non ce ne è traccia, sembra un argomento non trattato.

    ciaoooooooo
    nessuno

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.