 |
ไพสไม่ผ่าน มันหลุดเหมือนไม่มีไฟล์รับ เพราะอะไรครับ ของคุณครับ |
|
 |
|
|
 |
 |
|


ไฟล์ p1.php
Code (PHP)
<?
include("connect.php") ;
mysql_connect( $hostname,$username,$password) or die ("ไม่สามาติดต่ด Mysq ได้ ");
mysql_select_db($dbname) or die("ไม่สารถเลือกฐานข้อมูลได้");
mysql_query("SET NAMES UTF8");
$id =$_GET['id'];
$sql = "SELECT * FROM `bb_1` WHERE id ='$id'";
$dbquery = mysql_db_query($dbname, $sql);
while ($result = mysql_fetch_array($dbquery ))
{
$id = $result["id"];
$id_h = $result["id_h"];
$h1 = $result["h1"];
$b1 = $result["b1"];
$pig = $result["pig"];
$n1 = $result["n1"];
$d1 = $result["d1"];
$nu1 = $result["nu1"];
$ip = $result["ip"];
// $id $id_h $h1 $b1 $pig $n1 $d1 $nu1
/*
echo "id = $id<br>";
echo "เรื่่อง = $h1<br>";
echo "เนื้อหา = $id<br>";
echo "ภาพ = $pig<br>";
echo "ชื่อ = $n1<br>";
echo "วันที่ = $d1<br>";
echo "IP = $ip<br>"; */
}
$sql2 = "SELECT * FROM `bb_0` WHERE id_h ='$id_h'";
$dbquery2 = mysql_db_query($dbname, $sql2);
while ($result2 = mysql_fetch_array($dbquery2 ))
{
$hh = $result2["hh"];
$hb = $result2["hb"];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? echo "$b1 - $hh"; ?></title>
<style type="text/css">
<!--
body {
margin-top: 0px;
}
-->
</style></head>
<body>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="middle" bgcolor="#FFE88C"><? echo "$hh"; ?></td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#FFE88C"><? echo "สั่งงาน,ตรวจสอบแบบ,ยืนยันการสั่งปริ้นงาน, $hb"; ?></td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#FFEDA6"> </td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#FFEDA6"><? echo "ID$id $h1 "; ?></td>
</tr>
<tr>
<td bgcolor="#FFF2BF"><p align="center"> <?
if ($pig == "") {
} else{
echo "<img src='imgfile/$pig' />";
}
?></p>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><? echo " $b1"; ?></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><? echo " ชื่อ $n1 วันที่ $d1 , IP $ip";?></td>
</tr>
<tr>
<td> </td>
</tr>
</table> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<br>
<? $sql3 = "SELECT * FROM `bb_11` WHERE bb_11 ='$id' ORDER BY `bb_11`.`id11` ASC ";
$dbquery3 = mysql_db_query($dbname, $sql3);
while ($result3 = mysql_fetch_array($dbquery3))
{
$id11 = $result3["id11"];
$bb_11 = $result3["bb_11"];
$b11 = $result3["b11"];
$pig11 = $result3["pig11"];
$n11 = $result3["n11"];
$d11 = $result3["d11"];
$ip11 = $result3["ip11"];
$nu11 = $result3["nu11"];
$d++;
?>
<br>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#FFEDA6"><? echo " ||ความคิดเห็นที่ $d"; ?> </td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#FFEDA6"><?
if ($pig11 == "") {
} else{
echo "<img src='imgfile/$pig11' />";
}
?>
</td>
</tr>
<tr>
<td bgcolor="#FFEDA6"><? echo " $b11"; ?></td>
</tr>
<tr>
<td bgcolor="#FFEDA6"> </td>
</tr>
<tr>
<td bgcolor="#FFEDA6"><? echo " ชื่อ $n11 วันที่ $d11 IP $ip11"; ?></td>
</tr>
<tr>
<td bgcolor="#FFEDA6"> </td>
</tr>
</table>
<?
}
?>
<br />
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#FFEDA6"><form id="form1" name="form1" enctype="multipart/form-data" method="post" action="p2.php">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="21%" height="40"> </td>
<td width="79%" height="40"><label></label></td>
</tr>
<tr>
<td height="40">ภาพ</td>
<td height="40"><input name="Uploaded_File" type="file" id="Uploaded_File" > </td>
</tr>
<tr>
<td height="40">ข้อความ</td>
<td height="40"><label>
<textarea name="b11" cols="50" rows="3" id="b11"></textarea>
</label></td>
</tr>
<tr>
<td height="40">ชื่อผู้ส่ง</td>
<td height="40"><input name="n11" type="text" id="n11" />
<input name="id11" type="hidden" id="id11" value="<? echo "$id"; ?>" /></td>
</tr>
<tr>
<td height="40"> กรอกเลขสุ่มนี้
<?
function random_password($len)
{
srand((double)microtime()*10000000);
$chars = "abcd0123456789";
$ret_str = "";
$num = strlen($chars);
for($i = 0; $i < $len; $i++)
{
$ret_str.= $chars[rand()%$num];
$ret_str.="";
}
return $ret_str;
}
// echo random_password(8);
$passw = random_password(4);
echo $passw;
mysql_close();
?>
<input name="ck1" type="hidden" id="id112" value="<? echo "$passw"; ?>" />
<input name="id" type="hidden" id="ck1" value="<? echo "$id"; ?>" /></td>
<td height="40"><input name="ck2" type="text" id="ck2" /></td>
</tr>
<tr>
<td height="40"> </td>
<td height="40"><input type="submit" name="Submit" value="โพส" /></td>
</tr>
</table>
</form></td>
</tr>
</table>
<p> </p>
</body>
</html>
ไฟล์ p2.php
Code (PHP)
<?
include("connect.php") ;
mysql_connect( $hostname,$username,$password) or die ("ไม่สามาติดต่ด Mysq ได้ ");
mysql_select_db($dbname) or die("ไม่สารถเลือกฐานข้อมูลได้");
mysql_query("SET NAMES UTF8");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
margin-top: 0px;
background-color: #FF6600;
}
-->
</style></head>
<body><?
$id11 =$_POST['id11'];
$b11 =$_POST['b11'];
$n11 =$_POST['n11'];
$ck1 =$_POST['ck1'];
$ck2 =$_POST['ck2'];
$id =$_POST['id'];
echo " $id_h - $h1 - $b1 - $n1";
$today2=date("Y-m-d h.i:s");
$today3=date("Y-m-d_h-i-s_");
// $li =$_GET['li'];
$type = substr($_FILES['Uploaded_File']['name'],-4); // ค่าที่ได้จะเป็น .jpg,.png,.gif แต่ถ้าเป็นพวกไฟล์ office ที่มีนามสกุล 4 ตัวก็คงจะต้องหาวิธีอื่น
//สร้างชื่อไฟล์มาใหม่
if ($ck1 == $ck2) {
if ($Uploaded_File != "") // ตรวจสอบว่ามีไฟล์ส่งมาหรือไม่
{
if(strchr($Uploaded_File_name,".")==".JPG" ||
strchr($Uploaded_File_name,".")==".jpg" ||
strchr($Uploaded_File_name,".")==".GIF" ||
strchr($Uploaded_File_name,".")==".gif")
{
// copy($Uploaded_File,"imgfile/".$Uploaded_File_name); //Copy File ไว้ที่ Folder File
$new_name="$today3$id11".$type;
copy($Uploaded_File,"imgfile/".$new_name); //Copy File ไว้ที่ Folder File
echo " $new_name ไฟล์ถูก upload ไว้ที่โฟลเดอร์ imgfile";
} else{
echo "$new_name ไฟล์ที่ส่งมาไม่ใช่ไฟล์ .Gif และ .Jpg นะครับ";
} }
$formuser ="INSERT INTO `$dbname`.`bb_11` (
`id11` ,
`bb_11` ,
`b11` ,
`pig11` ,
`n11` ,
`d11` ,
`ip11` ,
`nu11`
)
VALUES (
NULL , '$id11', '$b11', '$new_name', '$n11', '$today2', '$REMOTE_ADDR', 'nu11'
);";
$dbquery = mysql_db_query($dbname, $formuser );
echo"<meta http-equiv='refresh' content='0;url=p1.php?id=$id'>";
}
else {
echo "<strong>กรอกเลขสุ่มไม่ถูกต้อง</strong>";
echo"<meta http-equiv='refresh' content='5;url=p1.php?id=$id'>";
}
mysql_close();
?>
</body>
</html>
ทำสอบบทเครื่องคอมผ่าน แต่ผอขึ้น server จริงหลุด เหมือนไม่มีไฟล์ p2.php
เพราะอะไรครับ ของคุณครับ
Tag : PHP, Linux, Web Service, Web Hosting
|
ประวัติการแก้ไข 2015-04-03 23:37:41
|
 |
 |
 |
 |
Date :
2015-04-02 20:35:22 |
By :
item170 |
View :
1556 |
Reply :
13 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ที่ไฟล์ .htaccess
เป็น
php_flag register_globals no
php_value display_errors on
แล้วก็ยังไม่ได้ครับ ต้องแก้ไขอย่างไรอีกครับ
|
 |
 |
 |
 |
Date :
2015-04-03 22:30:58 |
By :
item170 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Directive Local Value Master Value
allow_call_time_pass_reference On On
allow_url_fopen On On
allow_url_include Off Off
always_populate_raw_post_data Off Off
arg_separator.input & &
arg_separator.output & &
asp_tags Off Off
auto_append_file no value no value
auto_globals_jit On On
auto_prepend_file no value no value
browscap no value no value
default_charset no value no value
default_mimetype text/html text/html
define_syslog_variables Off Off
disable_classes no value no value
disable_functions exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
display_errors On On
display_startup_errors Off Off
doc_root no value no value
docref_ext no value no value
docref_root no value no value
enable_dl On On
error_append_string no value no value
error_log no value no value
error_prepend_string no value no value
error_reporting 22519 22519
exit_on_timeout Off Off
expose_php Off Off
extension_dir /usr/local/lib/php/extensions/no-debug-non-zts-20090626 /usr/local/lib/php/extensions/no-debug-non-zts-20090626
file_uploads On On
highlight.bg #FFFFFF #FFFFFF
highlight.comment #FF8000 #FF8000
highlight.default #0000BB #0000BB
highlight.html #000000 #000000
highlight.keyword #007700 #007700
highlight.string #DD0000 #DD0000
html_errors On On
ignore_repeated_errors Off Off
ignore_repeated_source Off Off
ignore_user_abort Off Off
implicit_flush Off Off
include_path .:/usr/local/lib/php .:/usr/local/lib/php
log_errors Off Off
log_errors_max_len 1024 1024
magic_quotes_gpc Off Off
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
mail.add_x_header On On
mail.force_extra_parameters no value no value
mail.log /home/mabuymas/.php/php-mail.log no value
max_execution_time 30 30
max_file_uploads 20 20
max_input_nesting_level 64 64
max_input_time 60 60
max_input_vars 5000 5000
memory_limit 128M 128M
open_basedir /home/mabas/:/tmp:/var/tmp:/usr/local/lib/php/:/usr/local/php53/lib/php/ no value
output_buffering 1 1
output_handler no value no value
post_max_size 64M 64M
precision 12 12
realpath_cache_size 16K 16K
realpath_cache_ttl 120 120
register_argc_argv On On
register_globals On Off
register_long_arrays On On
report_memleaks On On
report_zend_debug On On
request_order no value no value
safe_mode Off Off
safe_mode_exec_dir no value no value
safe_mode_gid Off Off
safe_mode_include_dir no value no value
sendmail_from no value no value
sendmail_path /usr/sbin/sendmail -t -i -f [email protected] /usr/sbin/sendmail -t -i
serialize_precision 100 100
short_open_tag On On
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
track_errors Off Off
unserialize_callback_func no value no value
upload_max_filesize 32M 32M
upload_tmp_dir no value no value
user_dir no value no value
user_ini.cache_ttl 300 300
user_ini.filename .user.ini .user.ini
variables_order EGPCS EGPCS
xmlrpc_error_number 0 0
xmlrpc_errors Off Off
y2k_compliance On On
zend.enable_gc On
|
 |
 |
 |
 |
Date :
2015-04-03 22:48:03 |
By :
item170 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กลับไปแก้ Code ให้มันถกต้องดีกว่าครับ อนาคตจะได้ไม่มีปัญหา
|
 |
 |
 |
 |
Date :
2015-04-04 07:52:53 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่มเติม
ขึ้นโฮสจริง คงใช้ <? แค่นี้ไม่ได้มั้งครับ น่าจะเป็น <?php
ผมว่า admin server เขาคงเปลี่ยน ไปใช้เต็มรูปแบบกันหมดแล้วมั้งครับ
|
 |
 |
 |
 |
Date :
2015-04-04 08:24:17 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมได้แก้ เป็น <?php แล้วก็ยังเหมือนเดิมครับ ต้องแก้ตรงไหมอีกครับ
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2015-04-04 10:58:58 |
By :
item170 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ของผมเป็นส่วนเพิ่มเติม หลักๆก็ตาม คุณวิน แอดมินครับ
คือใช้ตัวแปร global ไม่ได้
$Fileupload_name บนโฮสคงไม่รู้จัก
ให้เขียนเต็มๆ $_FILE['upload']['name']
|
 |
 |
 |
 |
Date :
2015-04-04 11:55:55 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไฟล์ form.php
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
ไฟล์ upload.php
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
ผมลองด้านบทนี้แล้ว กับserver ก็ไม่ได้
แต่ลองกับ server จำลองแล้วได้ไม่มีปัญหา
ขอลบกวนถามผู้รู้ ผิดตรงไหนครับ ช่วยแก้ให้ถูกต้องหน่วยนะครับ
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2015-04-04 19:52:21 |
By :
item170 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค๊ดถูกแล้วนะครับ ก็คงต้องดูที่ permission ว่ามีสิทธิ์ ในการ write file หรือเปล่า
หรือวาได้มีการสร้าง directory ขึ้นมารองรับหรือยัง
$target_dir = "uploads/"; // path ตัวสีแดง ได้สร้างขึ้น และกำหนด permission ไว้อย่างไรครับ
|
 |
 |
 |
 |
Date :
2015-04-05 10:20:50 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
777 เป็น ครับ
|
 |
 |
 |
 |
Date :
2015-04-06 15:29:03 |
By :
item170 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาคำสั่งข้างล้าง ไว้บันทัดแรก แล้วรองดู error ครับว่ามันบอกว่าอะไรบ้าง
error_reporting(E_ALL);
|
 |
 |
 |
 |
Date :
2015-04-06 15:46:26 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีอะไรเกิดขึ้นครับ
ไม่แสดงค่าอะไรมาเหมือนเดิมครับ
|
 |
 |
 |
 |
Date :
2015-04-07 23:15:06 |
By :
item170 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หมดมุขแล้วครับ เลยทำเป็นตัวอย่าง เอาโค๊ดของคุณ item170 มาประยุกต์เขียนให้ใหม่
ถ้าไม่ได้ ก็หมดมุขจริงๆ แล้วครับ
Code (PHP)
<?php
if(isset($_POST['submit'])){
$img='';
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
//echo $target_file; exit;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if(!$check) $img="File is not an image.";
// Check if file already exists
else if (file_exists($target_file)) $img="Sorry, file already exists.";
// Check file size
else if ($_FILES["fileToUpload"]["size"] > 500000) $img="Sorry, your file is too large.";
// Allow certain file formats
else if( !preg_match( '/(jpg|png|jpeg|gif)/i', $imageFileType)) {
$img="Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
}
// Check if $uploadOk is set to 0 by an error
if ( !$img) {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
$img="<img src='$target_file'> File has been uploaded.";
} else {
$img ="Sorry, there was an error uploading your file.";
}
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<form method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
<?=$img?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2015-04-08 08:46:57 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|