Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default binary data

    Greets,
    Register globals are to OFF - however the files will not upload.

    Thanking all in advance.
    TR
    ...............


    <?
    if ($submit) {

    // connect to the database
    // (you may have to adjust the hostname,username or password)

    MYSQL_CONNECT("localhost","root","mypass");
    mysql_select_db("mydb");

    $uploadfile = $_FILES['form_data']['tmp_name'];
    $uploadname = $_FILES['form_data']['name'];
    $uploadtype = $_FILES['form_data']['type'];
    $uploaddesc = $_POST['desc'];

    // Open file for binary reading ('rb')
    $tempfile = fopen($uploadfile,'rb');

    // Read the entire file into memory using PHP's
    // filesize function to get the file size.
    $filedata = fread($tempfile,filesize($uploadfile));

    // Prepare for database insert by adding backslashes
    // before special characters.
    $filedata = addslashes($filedata);

    // Create the SQL query.
    $sql = "INSERT INTO binary_data SET
    filename = '$uploadname',
    filetype = '$uploadtype',
    description = '$uploaddesc',
    bin_data = '$filedata'";

    $id= mysql_insert_id();

    print "<p>This file has the following Database ID: <b>$id</b>";
    echo "<br>";
    echo "<a href=\"getdata.php?id=$id\">Click to view file</a>";
    MYSQL_CLOSE();

    } else {

    // else show the form to submit new data:
    ?>

    <form method="post" action="<?php echo $PHP_SELF; ?>"
    enctype="multipart/form-data">
    <p>File Description:<br>
    <input type="text" name="desc" size="40">
    <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
    <br>File to upload/store in database:<br>
    <input type="file" name="form_data" size="40">
    <p><input type="submit" name="submit" value="submit">
    </form>
    <?php
    }
    ?>


    Lo Dolce Pesca Guest

  2. Similar Questions and Discussions

    1. Binary data transfer
      Hi i`m asked this question in several other websites but i don`t give an answer, ihope to give a right answer here. I need to use the...
    2. Webservices & binary data?
      Hi, We have a database that stores binary data such as word documents. Can these documents be delivered over Webservices by other applications...
    3. Freehand Binary Data
      When printing from my Freehand 9, I often get a message "Page contains EPS pictures which include binary data" What does this mean? I also have had...
    4. ASP Binary data transformation
      Hello, I'm using ADODB.Stream to open a binary file on the server and write it down to the browser using Response.BinaryWrite. It's working fine,...
    5. Is $data binary or ascii?
      Say I have a variable $data that has file contents in it. Is there a way to tell if it is binary or ascii? if($data =~ ???) { print "It is binary...
  3. #2

    Default Re: binary data

    On Thu, 15 Apr 2004 21:35:13 -0400, "Lo Dolce Pesca" <herefishyfishy@spam.org>
    wrote:
    >Register globals are to OFF - however the files will not upload.
    > // Prepare for database insert by adding backslashes
    > // before special characters.
    > $filedata = addslashes($filedata);
    >
    > // Create the SQL query.
    > $sql = "INSERT INTO binary_data SET
    > filename = '$uploadname',
    > filetype = '$uploadtype',
    > description = '$uploaddesc',
    > bin_data = '$filedata'";
    You've forgotten to actually execute the query.
    > $id= mysql_insert_id();
    --
    Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
    [url]http://www.andyh.co.uk[/url] / [url]http://www.andyhsoftware.co.uk/space[/url]
    Andy Hassall Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139