Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    35

    Question Uploading in Safe_Mode

    I'm currently making a script and I wish to upload files but my server is in safe_mode and I cannot change that.

    I want to know if it's possible to upload a file but instead of creating the file on the hard drive, I would store it inside a table in MySQL. If it is possible, where can I get some information or anything that would help me upload in safe_mode.
    Last edited by Chr1s; 09-14-2002 at 02:12 PM.
    EZScripts - Quality PHP Scripts, Low Price (includes Custom Scripting on request.)
    http://www.EZScripts.net/

  2. #2
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    I have no problem with this with safe mode enabled.

    The code in this tutorial will work with safe mode enabled... i've used and adapted it myself.

    http://www.phpbuilder.com/columns/florian19991014.php3

  3. #3
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    35

    Talking

    Thanks for the fast reply and thanks a LOT for that link

  4. #4
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    35

    Unhappy

    The tutorial was made with php3 could someone help me convert this to php4?

    PHP Code:
    <?php

    // store.php3 - by Florian Dittmer <[email protected]>
    // Example php script to demonstrate the storing of binary files into
    // an sql database. More information can be found at [url]http://www.phpbuilder.com/[/url]
    ?>

    <HTML>
    <HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
    <BODY>

    <?php
    // code that will be executed if the form has been submitted:

    if ($submit) {

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

        
    MYSQL_CONNECT("localhost","root","password");
        
    mysql_select_db("binary_data");

        
    $data addslashes(fread(fopen($form_data"r"), filesize($form_data)));

        
    $result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
            
    "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");

        
    $idmysql_insert_id();
        print 
    "<p>This file has the following Database ID: <b>$id</b>";

        
    MYSQL_CLOSE();

    } else {

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

        <form method="post" action="<?php echo $PHP_SELF?>" enctype="multipart/form-data">
        File Description:<br>
        <input type="text" name="form_description"  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

    }

    ?>

    </BODY>
    </HTML>

  5. #5
    Join Date
    Aug 2002
    Location
    San Jose, California
    Posts
    16
    It looks to me like it would work in php4 also... But I don't really know... You can always just label it script.php3 but if you want to use only parts of it... Copy some code snipets out and trial/error with it...
    -magz

  6. #6
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    It will work in PHP 4 with globa variables turned on in the php.ini

    To test this you can see it in the phpinfo(); function.

    However if you can't run that because your server admin has disabled it then try posting a field called 'test' from a form to a php script. If you can echo the value to the screen as $test then global variables is enabled and the script will work without any changes.

  7. #7
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    35
    my server has it disabled..

    lets say I wanted to do this:

    $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));

    $result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
    "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");


    i wont be able to do $form_data anymore cuz its empty... what do i do? $HTTP_POST_VARS['form_data'] ?

  8. #8
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    No the preferred method is $_POST['form_data']

  9. #9
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    35
    so if I wanted to get the $form_data_size variable I'd use $_POST['form_data_size'] ? You sure about that?
    EZScripts - Quality PHP Scripts, Low Price (includes Custom Scripting on request.)
    http://www.EZScripts.net/

  10. #10
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    Yes that is the php 4.1.x + method of using POST variables.

    http://www.php.net/manual/en/languag...predefined.php

    $_POST: Variables provided to the script via HTTP POST. Analogous to the old $HTTP_POST_VARS array (which is still available, but deprecated).

  11. #11
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    35
    Alright, I figured it all out and modified lots of it. Thanks for the help.

Posting Permissions

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