SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help...image uploading

    i downloaded the code below..this code is using php.ini's register_globals turned on. will anyone there can help me modify the code below so i don't need to turn the register_globals to ON?

    Code:
    <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')");
    
        $id= mysql_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>
    thanks in advance

    heigh

  2. #2
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You just need to make sure all your script's variables are initialized if you're going to have register globals off. For example,

    Code:
    $form_data = $_GET['form_data'];
    Also, you might want to also have a look at this page from the manual for a better understanding of just what the implications are for the way register globals is set on your server.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply vinyl...can i ask a favor?can u tell me what are the variables to be initialized in my codes??i tried to use $_POST and $_FILES but i always receive and error message.

    heigh

  4. #4
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As near as I can tell, here is your list of variables:

    $form_data
    $form_description
    $data
    $form_data_name
    $form_data_size
    $form_data_type

    BTW, that should be $_GET or $_POST to initialize them, not $_FILES.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh...ok...i'll try to get it right now.thanks very much.

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    problem...

    my code here is:
    Code:
    $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
    
        $result=MYSQL_QUERY("INSERT INTO binarydata (description,bindata,filename,filesize,filetype) ".
            "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
    i changed the form_description variable first into this:

    Code:
    "VALUES ('$_GET['form_description']','$data','$form_data_name','$form_data_size','$form_data_type')");
    i received this kind of error...
    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\inetpub\wwwroot\mysample\TMP7h47lbmrf8.php on line 19
    can u figure out the problem??

  7. #7
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For one thing, this isn't even a valid PHP statement:

    Code:
    "VALUES ('$_GET['form_description']','$data','$form_data_name','$form_data_size','$form_data_type')");
    Try this instead:

    Code:
    $form_description = $_GET['form_description'];
    $data = $_GET['data'];
    $form_data_name = $_GET['form_data_name'];
    $form_data_size = $_GET['form_data_size'];
    $form_data_type = $_GET['form_data_type'];
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  8. #8
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doh! I didn't look at your code very closely. I see that what you posted is part of one statement in your code.

    Just add the statements I posted to the top of your script and use the original statement you had for this:
    Code:
    $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_t  ype')");
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web


Bookmarks

Posting Permissions

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