Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 25th, 2004, 02:43 AM
Registered User
 
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default I need help with uploading file to mysql DB

my site is hosted by server that its REGISTRY GLOBLAS are OFF
Please read the code below, and tell me why cant I upload file to DB?
Its only upload the binary data but not the file name,size & type, can anyone tell my why ?

<HTML>
<HEAD><TITLE></TITLE></HEAD>
<BODY>

<?php
  $sub_price = $_POST['submit'];
  $idprice = $_POST['priceid'];
  $f_data = $_POST['form_data'];


  if (isset($sub_price)) {

     $p_date = date("W/Y");

     include("../dbconnect.php");

     $p_data = addslashes(fread(fopen($f_data, "rb"), filesize($f_data)));


     //inserting the file info to the first table.
     $result=mysql_query("REPLACE INTO price VALUES ('$idprice', '$f_data_name','$f_data_size','$f_data_type','$p_d ata','$p_date')");

     if (!$result) {
        die('Error inserting the file info');
     }

     echo

     "<center>File <b>$f_data_name</b> update successfully<BR><BR><a href='www.crg.co.il'>To CRG Site</a> ";

     mysql_close();

  } else {


?>


<FORM method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
      <p align="center" dir="ltr">&nbsp;
      <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">

      <INPUT TYPE="hidden" name="priceid" value="0">


      <span style="background-color: #FF0000">

      Price List UPDATE - Week <? echo date("W/Y") ?></span>

      <BR>
      <BR>
      <br>
      Price List File Upload - ONLY ZIP FILE !!!
      <br>
      <br>
      <INPUT type="file" name="form_data" size="20" dir="ltr">


      <INPUT type="submit" name="submit" value="submit">
      <INPUT type="reset" name="reset" value="reset">
      </P>
   </FORM>




<?php
  }
?>
</BODY>
</HTML>

 
Old June 26th, 2004, 08:34 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:Originally posted by superdos

Its only upload the binary data but not the file name,size & type, can anyone tell my why
You're using the wrong superglobal to access the data contained in the file. use the $_FILES superglobal, which is where information about the uploaded file is kept once the file reaches the server.

I wrote a tutorial on this exact topic, have a read of it:
http://p2p.wrox.com/topic.asp?TOPIC_ID=11883

You have a few other errors as well, $PHP_SELF isn't available if register_globals is turned off, you must access this from its superglobal array.. $_SERVER['PHP_SELF']

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old June 27th, 2004, 01:50 AM
Registered User
 
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very very much !!!! :D:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Uploading and downloading MySQL BLOB's Marcus Maximus PHP Databases 5 March 10th, 2008 11:32 PM
Uploading an image and storing its name in a DB SKE Classic ASP Databases 1 March 14th, 2005 09:13 AM
problem with uploading blob data to MySQL DB kyle_shea PHP Databases 1 March 8th, 2005 06:15 PM
Problem inserting blob data/uploading file - MySQL kyle_shea Beginning PHP 2 February 15th, 2005 10:18 AM
.NET C# wrox book on uploading files to a DB? jen6677 General .NET 2 November 9th, 2004 08:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.