حفظ الصور

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

PHP - http://ib.vbsq.net/index.php?

showtopic=793


.
.

: :
PHP Function

is_uploaded_file
$_FILES
include
file_get_contents
addslashes

MySQL PHP

mysql_connect
mysql_error
mysql_select_db
mysql_query
mysql_fetch_row

SQL

CREATE DATABASE database_name


CREATE TABLE
INSERT INTO
SELECT * From Table

phpmyadmin :

1 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793


SQL

SQL

: :

MySQL :
: BLOB A -
CREATE DATABASE : SQL B -
CREATE TABLE : SQL C -
:
SQL - 1 phpmyadmin
phpmyadmin 2 -
PHP :

:
- 1 PHP :
- 2 PHP :
- 3 PHP :
- 4 PHP :
- 5 :


:
PHP MySQL
.
, 4.3.0 PHP
5
3.21 MySQL
PHP_Designer_2008_Professional

: HnHn: 13 September 2008 - 08:33 PM

1 1


2 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

D.Mourad

September 2008 - 06:13 PM 13

MySQL :
.
BLOB : [A] -
Binary BLOB
Large Object
BLOB : MYSQL

BLOB
TINYBLOB
MEDIUMBLOB
LONGBLOB

CREATE DATABASE : SQL [B] -


CREATE DATABASE database_name

database_name : .
up_image_db

CREATE DATABASE up_image_db

CREATE TABLE : SQL [C] -


CREATE TABLE table_name


(

3 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

(
column_name1 data_type option,
column_name2 data_type option,
.......
)

. table_name :
. column_name1 :
. data_type :
option : .

images :

( `CREATE TABLE `images


`img_id` INT NOT NULL AUTO_INCREMENT ,
`img_nom` VARCHAR( 50 ) NOT NULL ,
`img_taille` VARCHAR( 25 ) NOT NULL ,
`img_type` VARCHAR( 25 ) NOT NULL ,
`img_desc` VARCHAR( 100 ) NOT NULL ,
`img_blob` BLOB NOT NULL ,
) `PRIMARY KEY ( `img_id
)

6 :
AUTO_INCREMENT NOT NULL INT img_id

NOT NULL 50 ) VARCHAR( 50 img_nom


NOT 25 ) VARCHAR( 25 img_taille
NULL
NOT NULL 25 ) VARCHAR( 25 img_type
NOT 100 ) VARCHAR( 100 img_desc
NULL
NOT NULL BLOB img_blob

img_id ) ` PRIMARY KEY ( `img_id


mysql_query . - 1 PHP
. - 2 phpmyadmin

: HnHn: 13 September 2008 - 08:13 PM

D.Mourad

4 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

September 2008 - 06:48 PM 13

SQL : - [1] phpmyadmin


: http://localhost/phpmyadmin/index.php

x 546) - ) %84 837

:
x 545) - ) %85 835

5 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

up_image_db

;`CREATE DATABASE `up_image_db


x 546) - ) %84 837

: 1 0.0038
: 2
0 up_image_db , : 3

6 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

0 up_image_db , : 3

images
: 4 :
x 546) - ) %84 837

SQL SQL SQL


x 546) - ) %84 837

7 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

SQL images

CREATE TABLE `images` (


`img_id` INT NOT NULL AUTO_INCREMENT ,
`img_nom` VARCHAR( 50 ) NOT NULL ,
`img_taille` VARCHAR( 25 ) NOT NULL ,
`img_type` VARCHAR( 25 ) NOT NULL ,
`img_desc` VARCHAR( 100 ) NOT NULL ,
`img_blob` BLOB NOT NULL ,
PRIMARY KEY ( `img_id` )
)

837 )%84 x 546) -

: 1
: 2

8 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

: 2

: 0 1
images : 4
phpmyadmin

phpmyadmin : [2] -
: http://localhost/phpmyadmin/index.php

:
x 546) - ) %84 837

:
x 546) - ) %84 837

9 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

: 1
phpmyadmin SQL : 2

up_image_db .
Image :
:

x 546) - ) %84 837

10 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

- 1 images
2 - 6
- 3
:
.
x 545) - ) %85 835

.
:
x 546) - ) %84 837

11 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

: 1
phpmyadmin SQL : 2
: 3 6 .
up_image_db images : 4


PHP

: HnHn: 13 September 2008 - 08:15 PM

D.Mourad

September 2008 - 07:15 PM 13

PHP :

PHP
UP_IMAGES PHP
PHP :

:

HTML :

><html
><head
></title ><title
></head
><body
></h3 ><h3
>"<form enctype="multipart/form-data" action="#" method="post
><input type="hidden" name="MAX_FILE_SIZE" value="250000" /
><input type="file" name="fic" size=50 /
>" /"=<input type="submit" value
></form

12 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

></form
></body
></html

UP_IMAGES . index.php
250000 MAX_FILE_SIZE .
HTTP POST
PHP .
:
x 545) - ) %84 837

PHP ,
:

: PHP
[A] -
[B] -
[C] -
[D] -
[E] -

13 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

- [1] PHP :

<?php
;$ret = false
;)]'$ret = is_uploaded_file ($_FILES['fic']['tmp_name
) if ( !$ret
{
;" " echo
;return false
}
else
{
...
...
...
}
>?

:
$_FILES :
HTTP POST :

]'$_FILES['userfile']['name
]'$_FILES['userfile']['size
]'$_FILES['userfile']['type
]'$_FILES['userfile']['tmp_name

HTML : userfile :

fic HTML

><input type="file" name="fic" size=50 /

name :

octets size :
type :
tmp_name :

is_uploaded_file :
FLASE . HTTP POST TRUE

) bool is_uploaded_file ( string filename
filename :

14 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

filename :
: 10 PHP

;)]'$ret = is_uploaded_file ($_FILES['fic']['tmp_name

FALSE TRUE $ret :


HTML fic :
tmp_name :

: - [2] PHP

<?php
;$taille_max = 250000
;]'$img_taille = $_FILES['fic']['size
) if ( $img_taille > $taille_max
{
;"! " echo
}
>?

$taille_max :
) ( $img_taille :

- [3] PHP :

;'' = $img_blob
;)]'$img_blob = file_get_contents ($_FILES['fic']['tmp_name

file_get_contents :
:
) file_get_contents ( string filename
filename
filename : .

- [4] PHP :

15 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

- [4] PHP :
connexion.php
:

<?php
;'$hote = 'localhost
;'$base = 'up_image_db
;'$user = 'root
;'' = $pass
;))( $cnx = mysql_connect ($hote, $user, $pass) or die (mysql_error
;))( $ret = mysql_select_db ($base) or die (mysql_error
>?

:
x 600) - ) %84 837

connexion.php : 1
MySQL : 2

up_image_db : 3
MySQL : 4

16 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

: 5 MySQL


mysql_connect :
TRUE MySQL
:
mysql_connect (string server , string username , string password )
string server :
string username : MySQL
string password : MySQL

mysql_error :

mysql_select_db :

bool mysql_select_db ( string database_name )

string database_name :

: - [5]

$req = "INSERT INTO images (".


"img_nom, img_taille, img_type, img_blob ".
") VALUES (".
"'".$img_nom."', ".
"'".$img_taille."', ".
"'".$img_type."', ".
"'".addslashes ($img_blob)."') ";
$ret = mysql_query ($req) or die (mysql_error ());

17 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

INSERT INTO :

:

)INSERT INTO table_name (column1, column2,...


)VALUES (value1, value2,....

table_name :
column1 :
column1 value1 :

addslashes :
PHP "\" " '

mysql_query :
MySQL SQL
) mysql_query ( string query

SQL string query :

A B C E :

<?php
)( function transfert
{
;$ret = false
;'' = $img_blob
;$img_taille = 0
;'' = $img_type
;'' = $img_nom
;$taille_max = 250000
;)]'$ret = is_uploaded_file ($_FILES['fic']['tmp_name
) if ( !$ret
{
;" " echo
;return false
}
else
{
;]'$img_taille = $_FILES['fic']['size
) if ( $img_taille > $taille_max
{
;"! " echo
;return false
}

18 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

}
$img_type = $_FILES['fic']['type'];
$img_nom = $_FILES['fic']['name'];

$img_blob = file_get_contents ($_FILES['fic']['tmp_name']);


include ("connexion.php");
$req = "INSERT INTO images (img_nom, img_taille, img_type, img_blob ) VALUES
('".$img_nom."', '".$img_taille."', '".$img_type."',
'".addslashes ($img_blob)."') ";
$ret = mysql_query ($req) or die (mysql_error ());
return true;
}
}
?>

:
837 )%84 x 800) -

19 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

: 1 transfert.php

include :
PHP
:
include( string filename )
string filename : .

index.php :

<html>
<head>
<title>< /title>
</head>
<body>
<?php
include ("transfert.php");
if ( isset($_FILES['fic']) )
{
transfert();
}
?>

<h3>< /h3>
<form enctype="multipart/form-data" action="#" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="250000" />
<input type="file" name="fic" size=50 />
<input type="submit" value=" "/>
</form>
</body>
</html>

:
837 )%84 x 545) -

20 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

: HnHn: 13 September 2008 - 08:16 PM

D.Mourad

13 September 2008 - 07:27 PM


PHP liste.php
:

<html>
<head><title>< /title></head>
<body>
<?php
include ("connexion.php");
$req = "SELECT img_nom, img_id FROM images ORDER BY img_nom";
$ret = mysql_query ($req) or die (mysql_error ());

while ( $col = mysql_fetch_row ($ret) )


{
echo "<a href=\"apercu.php?id=".$col[1]."\">".$col[0]."</a><br />";
}
?>
</body>
</html>


837 )%84 x 545) -

21 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

mysql_fetch_row : 11



array mysql_fetch_row ( resource result )

resource result : mysql_query

13 apercu.php

php apercu.php
:

<?php
if ( isset($_GET['id']) )
{
$id = intval ($_GET['id']);
include ("connexion.php");
$req = "SELECT img_id, img_type, img_blob FROM images WHERE img_id = ".$id;
$ret = mysql_query ($req) or die (mysql_error ());

22 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

$ret = mysql_query ($req) or die (mysql_error ());


$col = mysql_fetch_row ($ret);
if ( !$col[0] )
{
echo ";"
}
else
{
header ("Content-type: ".$col[1]);
echo $col[2];
}
}
else
{
echo ";"
}
?>

index.php

<html>
<head>
<title>< /title>
</head>
<body>

<?php
include ("transfert.php");
if ( isset($_FILES['fic']) )
{
transfert();
}
?>

<h3>< /h3>
<form enctype="multipart/form-data" action="#" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="250000" />
<input type="file" name="fic" size=50 />
<input type="submit" value=" "/>
</form>
<p><a href="liste.php">< /a></p>
</body>
</html>

:
837 )%84 x 545) -

23 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com
PHP - http://ib.vbsq.net/index.php?showtopic=793

24 24 11-01-2011 13:28
PDF created with pdfFactory Pro trial version www.pdffactory.com

You might also like