如何从表sob
数据字段articles
中的当前数据库id
的当前记录中读取以下代码并将其写入$current_id
?
一般来说,我想更改上传文件的文件名,总是首先是" ID2" (此ID2不会更改当前操作),然后是文件名。
以下代码仅为$ new_id
提供了000000
我因为一周被封锁而且不知道。我尝试了很多东西。我读了这么多。我学到了很多,但我没有得到结果。令人沮丧......
这是" body_articles.php"
中的html代码 <?php session_start();
$_db_host = "localhost";
$_db_username = "admin0";
$_db_passwort = "dfgfghxyxc";
$_db_datenbank = "sob";
# Verbindung zur Datenbank herstellen
$_link = mysql_connect($_db_host, $_db_username, $_db_passwort);
# Pr�fen ob die Verbindung geklappt hat
if (!$_link)
{
# Nein, also das ganze Skript abbrechen !
die("Keine Verbindung zur Datenbank m�glich: " .
mysql_error());
}
# Datenbank ausw�hlen
mysql_select_db($_db_datenbank, $_link);
?>
<!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" dir="ltr" lang="en-US">
<head>
<meta charset="UTF-8" />
<title>SoB - Administration</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript" src="js/multiupload.js"></script>
<script type="text/javascript">
var config =
{
support : "image/jpg,image/png,image/bmp,image/jpeg,image/gif", // Valid file formats
form: "demoFiler", // Form ID
dragArea: "dragAndDropFiles", // Upload Area ID
uploadUrl: "upload.php" // Server side upload url
}
$(document).ready(function(){
initMultiUploader(config);
});
$(document).ready(function() {
var storedFiles = [];
$('#myfiles').on('change', function() {
$('#messages').html('');
var myfiles = document.getElementById('myfiles');
var files = myfiles.files;
var i=0;
alert("files uploading");
for (i = 0; i<files.length; i++) {
var readImg = new FileReader();
var file=files[i];
if(file.type.match('image.*')){
storedFiles.push(file);
readImg.onload = (function(file) {
return function(e) {
$('#uploadedfiles').append('<tr class="imageinfo"><td><img width="80" height="70" src="'+e.target.result+'"/></td><td>'+file.name+'</td><td>'+Math.round((file.size/1024))+'KB</td><td><a href="" class="lnkcancelimage" file="'+file.name+'" title="Cancel"><img src="delete.png" width=34" height="34"/></a></td></tr>');
};
})(file);
readImg.readAsDataURL(file);
}else{
alert('the file '+file.name+' is not an image<br/>');
}
}
});
$('#uploadedfiles').on('click','a.lnkcancelimage',function(){
$(this).parent().parent().html('');
var file=$(this).attr('file');
var strID = myTrim(document.demoFiler.ID2.value);
for(var i=0;i<storedFiles.length;i++) {
if(storedFiles[i].name == file) {
storedFiles.splice(i,1);
break;
}
}
return false;
});
$('#lnkupload').click(function(){
var data = new FormData();
var i=0;
for(i=0; i<storedFiles.length; i++) {
data.append('files'+i,storedFiles[i]);
}
if(i>0){
$.ajax({
url: 'load.php',
type: 'POST',
contentType: false,
data: data,
processData: false,
cache: false
}).done(function(msg) {
storedFiles = [];
if(msg){
alert(msg);
}else{
$('#messages').html('Images uploaded successfully');
}
}).fail(function() {
alert('error');
});
}
return false;
});
});
function jsShowArticle() {
js_articles = JSON.parse(json_string);
$('[name="recordCurrent"]').attr("id",js_articles[0]);
document.demoFiler.ID2.value = js_articles[0];
}
</SCRIPT>
<style type="text/css">.buttonarea: (\a)</style>
</head>
<body class="page page-id-11505 page-template-default" onload="jsShowArticle();">
<div id="page-wrap">
<?php
include('includes/header.html');
?>
<div id="container-main">
<div id="main-content">
<div class="post" id="post-11505">
<title>SoB - Administration</title>
<div class="entry">
<div id="dragAndDropFiles" class="uploadArea">
<br>
<span style="padding-left: 20px">To upload more pictures for this item click Browse</span>
<br>
<span style="padding-left: 20px">The order of the upload decide the order to show the pictures</span>
</div>
<form name="demoFiler" id="demoFiler" enctype="multipart/form-data" style="">
<input id="ID2" type="text" name="ID2name">
<input type="file" name="multiUpload" id="multiUpload" multiple />
<input type="submit" name="submitHandler" id="submitHandler" value="Upload" class="buttonUpload" />
</form>
<div class="progressBar">
<div class="status"></div>
</div>
</div>
</div>
</div>
<div id="aside">
</div>
<br class="clearfloat" />
</div> <!-- End of main container -->
</div><!-- END Page Wrap -->
<div id="footer">
<br class="clearfloat" />
<?php
if(isset ($_SESSION['name']))
{
$loginTitle="Logout";
$loginLink="body_logout.php";
}
else
{
$loginTitle="Login";
$loginLink="body_login.php";
}
?>
</div>
</body>
</html>
文件upload.php
<?php
$link = mysql_connect('localhost', 'admin0', 'fdhfuirkfk');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('sob', $link);
if (!$db_selected) {
die('Can\'t use foo : ' . mysql_error());
}
$current_id = (int)$_REQUEST['currentRecord']; // here is Your current_id
// if You're just getting data so You echo result from db
if($_SERVER['REQUEST_METHOD'] == "GET"){
$result = mysql_query("SELECT * FROM articles WHERE id > " . $current_id . " ORDER BY id ASC LIMIT 1");
$result = mysql_fetch_row($result);
echo json_encode($result);
exit(0);
}
// and there You're pushing file and echo $_POST['index']
if($_SERVER['REQUEST_METHOD'] == "POST"){
$new_id = sprintf( "%06d", $current_id);
if(move_uploaded_file($_FILES['file']['tmp_name'], "sobimages/" . $new_id . $_FILES['file']['name'])){
echo($_POST['index']);
}
exit(0);
}?>
如何从表单字段ID2
获取值,将此值读入$new_id
upload.php
文件而不干扰其他操作?
最后一个文件是nextarticle.php
。它与多文件上载无关,我发帖就是提供更多信息。它读了下一张唱片。
<?php
$link = mysql_connect('localhost', 'admin0', 'fdhfuirkfk');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('sob', $link);
if (!$db_selected) {
die('Can\'t use foo : ' . mysql_error());
}
$current_id = $_REQUEST['currentRecord'];
$result = mysql_query("SELECT * FROM articles WHERE id > " . $current_id . " ORDER BY id ASC LIMIT 1");
$result = mysql_fetch_row($result);
echo json_encode($result);
?>
答案 0 :(得分:1)
试试这个:
$link = mysql_connect('parsley.arvixe.com:3306', 'admin0', 'fdhfuirkfk');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('sob', $link);
if (!$db_selected) {
die('Can\'t use foo : ' . mysql_error());
}
$current_id = (int)$_REQUEST['currentRecord']; // here is Your current_id
// if You're just getting data so You echo result from db
if($_SERVER['REQUEST_METHOD'] == "GET"){
$result = mysql_query("SELECT * FROM articles WHERE id > " . $current_id . " ORDER BY id ASC LIMIT 1");
$result = mysql_fetch_row($result);
echo json_encode($result);
exit(0);
}
// and there You're pushing file and echo $_POST['index']
if($_SERVER['REQUEST_METHOD'] == "POST"){
$new_id = sprintf( "%06d", $current_id);
if(move_uploaded_file($_FILES['file']['tmp_name'], "sobimages/" . $new_id . $_FILES['file']['name'])){
echo($_POST['index']);
}
exit(0);
}