|
|
|
ช่วย หน่อยครับ คือผมทำ สคริปอัพรูปลงดาต้าครับ php7 แต่ผมอยากให้มันจัดการขนาดรูปอัตโนมัตอะครับ เช่นขนาด 1000px * 500px |
|
|
|
|
|
|
|
สคริปอัพรูปลงดาต้าครับ php7 แต่ผมอยากให้มันจัดการขนาดรูปอัตโนมัตอะครับ เช่นขนาด 1000px * 500px
สคริปใช้ได้ครับ แก้อยากได้มันแก้ขนานอ้อโต้
Code (SQL)
CREATE TABLE `files` (
`FilesID` int(4) NOT NULL auto_increment,
`Name` varchar(100) NOT NULL,
`FilesName` varchar(100) NOT NULL,
PRIMARY KEY (`FilesID`)
) ENGINE=MyISAM AUTO_INCREMENT=3 ;
--
-- Dumping data for table `files`
--
INSERT INTO `files` VALUES (1, 'win', 'win.jpg');
INSERT INTO `files` VALUES (2, 'plakrim', 'plakrim.jpg');
Code (config.php)
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connection = "localhost";
$database_connection = "123456";
$username_connection = "root";
$password_connection = "root";
$connection = mysqli_connect($hostname_connection, $username_connection, $password_connection, $database_connection) or trigger_error(mysqli_connect_errno(),E_USER_ERROR);
mysqli_set_charset($connection, "utf8");
?>
Code (Slide1.php)
<html>
<head>
</head>
<body>
<form name="form1" method="post" action="Slide2.php" enctype="multipart/form-data">
Name : <input type="text" name="txtName"><br>
Picture : <input type="file" name="filUpload"><br>
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>
Code (Slide2.php)
<html>
<head>
<?php
include"config.php";
?>
</head>
<body>
<?
if($_FILES["filUpload"]["name"] != "")
{
if(copy($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
//*** Insert Record ***//
$strSQL = "INSERT INTO files ";
$strSQL .="(Name,FilesName) VALUES ('".$_POST["txtName"]."','".$_FILES["filUpload"]["name"]."')";
$objQuery = mysqli_query($connection,$strSQL);
}
?>
<a href="Slide3.php">View files</a>
</body>
</html>
Code (Slide3.php)
<html>
<head>
<?php
include"config.php";
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<?
$strSQL = "SELECT * FROM files";
$objQuery = mysqli_query($connection,$strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="340" border="1">
<tr>
<th width="50"> <div align="center">Files ID </div></th>
<th width="150"> <div align="center">Picture</div></th>
<th width="150"> <div align="center">Name</div></th>
<th width="150"> <div align="center">Edit</div></th>
</tr>
<?
while($objResult = mysqli_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["FilesID"];?></div></td>
<td><center><img src="myfile/<?=$objResult["FilesName"];?>"></center></td>
<td><center><?=$objResult["Name"];?></center></td>
<td><center><a href="Slide4.php?FilesID=<?=$objResult["FilesID"];?>">Edit</a></center></td>
</tr>
<?
}
?>
</table>
<?
mysqli_close($connection);
?>
</body>
Code (Slide4.php)
<html>
<?php
include"config.php";
?>
<body>
<?
$strSQL = "SELECT * FROM files WHERE FilesID = '".$_GET["FilesID"]."' ";
$objQuery = mysqli_query($connection,$strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysqli_fetch_array($objQuery);
?>
<form name="form1" method="post" action="Slide5.php?FilesID=<?=$_GET["FilesID"];?>" enctype="multipart/form-data">
Edit Picture :<br>
Name : <input type="text" name="txtName" value="<?=$objResult["Name"];?>"><br>
<img src="myfile/<?=$objResult["FilesName"];?>"><br>
Picture : <input type="file" name="filUpload"><br>
<input type="hidden" name="hdnOldFile" value="<?=$objResult["FilesName"];?>">
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>
Code (Slide5.php)
<html>
<head>
<?php
include"config.php";
?>
</head>
<body>
<?
//*** Update Record ***//
$strSQL = "UPDATE files ";
$strSQL .=" SET NAME = '".$_POST["txtName"]."' WHERE FilesID = '".$_GET["FilesID"]."' ";
$objQuery = mysqli_query($connection,$strSQL);
if($_FILES["filUpload"]["name"] != "")
{
if(copy($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
{
//*** Delete Old File ***//
@unlink("myfile/".$_POST["hdnOldFile"]);
//*** Update New File ***//
$strSQL = "UPDATE files ";
$strSQL .=" SET FilesName = '".$_FILES["filUpload"]["name"]."' WHERE FilesID = '".$_GET["FilesID"]."' ";
$objQuery = mysqli_query($connection,$strSQL);
echo "Copy/Upload Complete<br>";
}
}
?>
<a href="Slide3.php">View files</a>
</body>
</html>
Tag : PHP
|
ประวัติการแก้ไข 2018-04-17 16:48:46
|
|
|
|
|
Date :
2018-04-17 16:47:20 |
By :
skyblack2009 |
View :
658 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|