Forum Moderators: coopster

Message Too Old, No Replies

how can I load image files in my db and call from php?

         

rekhad

2:14 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



I want to load image files in my database so that a user can open it or can add new image to the db.Can someone help me out?My image files are big about 5-10MB

rekhad

3:55 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



I need help i am very new to php/mysql.Is there any tutorial for loading videos in db and accessing and through a php cript

philestine

4:54 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



do you need to actually load them into the database or could you just insert a link?

rekhad

5:02 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



I can provide a link too,but if a user is authourised to load a video it should reside on a database.Correct me if I am wrong.I want to keep my videos at one place so that a user can have access to them.

jatar_k

5:47 pm on Mar 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



keep your videos in a directory and just store the path to the video, or just the filename, in your database

rekhad

7:26 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



can you show the commands to do that or send a link.I am new and still learning..

jatar_k

7:31 pm on Mar 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can find some examples for uploading, in this case images

[webmasterworld.com...] - msg 29

there are a bunch of threads about mysql in the PHP Library [webmasterworld.com]

rekhad

8:03 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



I will look at the example try to understand it then try it and will get back to the forum if I am stuck.
I
s video upload too much different from image upload?
I also read about saving images in binary in the db.
What method is usually prefered if files are big?(5-10MB)

jatar_k

10:21 pm on Mar 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



saving images in your db is just a bad idea, imagine how quickly your db becomes huge and the amount of data you are moving around when you store a couple of 5MB files in there.

just store the path/filename

coopster

1:30 am on Mar 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



A similar discussion that may be helpful

[webmasterworld.com...]

Note: There is a spin-off thread in there that discusses the very topic in which jatar_k is referring.

rekhad

7:11 pm on Mar 5, 2006 (gmt 0)

10+ Year Member



In the following code I am getting error that the variable submit is not defined.How to define it in a right way?


<html>
<head><title>Store binary data into SQL Database</title></head>
<body>
<?php
// code that will be executed if the form has been submitted:
require "db1.inc";

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_name, "r"), filesize($form_data_name)));

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

<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_name" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
?>


<?php

}

?>

</body>
</html>

coopster

9:48 pm on Mar 5, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It is an index in the $_POST superglobal.
if (isset [php.net]($_POST [php.net]['submit'])) {

rekhad

10:46 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



I saw the following code by Birdman,but I am not able to follow all the commands.I am sure they are basic commands but still if someone can help me out it will be nice.I tried to understand from http:\\www.php.net but I am not very clear

[webmasterworld.com...]

-----------------------------------------------------

What does the following if statements mean?
1.if ($_FILES['userfile']['name'][$q] == "")

2.if (move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir . $new_pic))

What is $source_x $source_y representing?

3.$source_x = $picsize[0];
$source_y = $picsize;
if ($source_x > $source_y){
$dest_x = 200;
$dest_y = 150;
} else {
$dest_x = 150;
$dest_y = 200;
}
How is name defined here?
4.<input type="text" name="pic_name[<?=$num?>]"

[edited by: coopster at 12:10 am (utc) on Mar. 7, 2006]
[edit reason] snipped code, provided link [/edit]