How can I convert a image to text code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ajm113
    New Member
    • Jun 2007
    • 161

    How can I convert a image to text code?

    Ok, I want allow the user to use their own background image for their home page and I want to do something like this. Where when the image is uploaded it will translate into text data and will be saved in a cookie so when ever the user comes back the image will display on the home page:



    Any links or code?

    Thanks, Ajm.
    Last edited by pbmods; Nov 4 '07, 01:43 PM. Reason: Fixed link.
  • post
    New Member
    • Sep 2007
    • 17

    #2
    Originally posted by Ajm113
    Ok, I want allow the user to use their own background image for their home page and I want to do something like this. Where when the image is uploaded it will translate into text data and will be saved in a cookie so when ever the user comes back the image will display on the home page:

    http://software.hixie. ch/utilities/cgi/data/data

    Any links or code?

    Thanks, Ajm.
    Here is a simple upload script that will allow certain files to be uploaded, after upload you can execute a query to the path of the image in the users information.

    Page name: x.php

    [php]
    <?php

    $target = "upload/path/insert/here/";
    $target = $target . basename( $_FILES['file']['name']);

    $image=($_FILES['file']['name']);

    if (chk_file($imag e)) { $error = "Invalid Extension"; echo("<pre><cen ter>"); echo($error); echo("</pre></center>"); exit; }

    if($_POST['file'] == "") { $error = "Please upload your file."; }

    if(!chk_file($i mage) && move_uploaded_f ile($_FILES['file']['tmp_name'], $target) && isset($image))
    {
    $error = "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded.";
    //echo("<img src=\"{$target} \">");
    //Insert mysql statement here
    echo($error);
    }
    elseif (is_uploaded_fi le($_FILES['file']['tmp_name']) == FALSE && $_POST['file'] != "") {
    $error = "Sorry, there was a problem uploading your file.";
    }
    ?>
    <?php
    function chk_file($file) {
    $approve = Array('1' => '.JPG', '2' => '.GIF', '3' => '.PNG');
    $deny = Array('1' => '.exe', '2' => '.php');
    $str = strtoupper($fil e);

    foreach ($approve as $id=>$ext) {
    if (preg_match("/$ext/i", $str)) {
    $status = false;
    }
    }
    foreach ($deny as $id=>$ext) {
    if (preg_match("/$ext/i", $str)) {
    $status = true;
    }
    }
    return $status;
    }
    ?>
    [/php]
    [html]
    <center>
    <?php echo($error); ?>
    <pre>
    <form action="x.php" method="POST" enctype="multip art/form-data" class="style2">
    <div align="center">
    File: <input type="file" name="file"><br >
    <input name="Submit" type="submit" class="style1" value="Add"><br />
    </div>
    </form>
    </pre>
    </center>
    [/html]

    Comment

    • Ajm113
      New Member
      • Jun 2007
      • 161

      #3
      I was playing around with the code and reversed the functions to uptop in your first script snipit to see if I could get rid of these errors:

      I have php 4 (I think)


      Notice: Undefined index: file in Path/Path

      Notice: Undefined index: uploadedfile in Path/Path

      Can you help me out? It's been a while since I have touched php.

      Comment

      • post
        New Member
        • Sep 2007
        • 17

        #4
        Originally posted by Ajm113
        I was playing around with the code and reversed the functions to uptop in your first script snipit to see if I could get rid of these errors:

        I have php 4 (I think)


        Notice: Undefined index: file in Path/Path

        Notice: Undefined index: uploadedfile in Path/Path

        Can you help me out? It's been a while since I have touched php.
        What I think that is you forgot to change the variable $target to where you want to upload the files. Easier to narrow it down if you have the exact line # the error takes place on.

        Comment

        Working...