Web Hosting Talk







View Full Version : Uploading in Safe_Mode


Chr1s
09-14-2002, 02:06 PM
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.

Rich2k
09-14-2002, 02:15 PM
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

Chr1s
09-14-2002, 02:24 PM
Thanks for the fast reply and thanks a LOT for that link :)

Chr1s
09-14-2002, 03:08 PM
The tutorial was made with php3 could someone help me convert this to php4? :( :(


<?php

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

<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>

mAgz
09-14-2002, 03:51 PM
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...

Rich2k
09-14-2002, 07:38 PM
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.

Chr1s
09-15-2002, 11:56 AM
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'] ?

Rich2k
09-15-2002, 02:23 PM
No the preferred method is $_POST['form_data']

Chr1s
09-15-2002, 04:24 PM
so if I wanted to get the $form_data_size variable I'd use $_POST['form_data_size'] ? You sure about that?

Rich2k
09-15-2002, 06:49 PM
Yes that is the php 4.1.x + method of using POST variables.

http://www.php.net/manual/en/language.variables.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).

Chr1s
09-15-2002, 09:50 PM
Alright, I figured it all out and modified lots of it. Thanks for the help.