我需要一些關於PHP類的幫助。我對它的工作原理知之甚少,並試圖發現更多。同時,我遇到了一個問題,我需要在通過類中的這些函數運行之後獲取變量。PHP類 - 將變量發送到插入查詢
protected function upcount_name_callback($matches) {
$index = isset($matches[1]) ? intval($matches[1]) + 1 : 1;
$ext = isset($matches[2]) ? $matches[2] : '';
return ' ('.$index.')'.$ext;
}
protected function upcount_name($name) {
return preg_replace_callback(
'/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/',
array($this, 'upcount_name_callback'),
$name,
1
);
}
我需要在下面的JS語句中檢索這個變量併發送到我的INSERT php文件。
$('#albumBack.fileupload').bind('fileuploaddone',function(e,data) {
//Loop through each page and return object and write to DB
$.each(data.files, function (index, file) {
var filename = file.name;
$.ajax({
type: "POST",
url: "../albumUploader/queries/albumPages.php",
data: {file: filename}
});
});
});
我目前得到的文件名是原始名稱,而不是附加名稱。 感謝您的任何幫助。
albumPages.php
//Variables for gallerimage table
$originalName = $_POST['file'];
$clientRef = $_SESSION['clientRef'];
$galleryID = $_SESSION['newGalleryId'];
$galleryLayout = $_SESSION['layoutID'];
$imageID = rand();
//Find the sort# for the gallery
$qSortOrder = mysql_query("SELECT MAX(sort) AS sortOrder
,id
,clientRef
,galleryId
FROM galleryimage
WHERE galleryId='{$galleryID}'
AND clientRef= '{$clientRef}'
");
$fsortOrder = mysql_fetch_array($qSortOrder);
//Latest revision
$orderNumber = $fsortOrder['sortOrder'];
$order = $orderNumber + 1;
$query = "INSERT INTO galleryimage
(
galleryId
,image
,OrgImageName
,clientRef
,sort
,layout
) VALUES (
'{$galleryID}'
,'{$imageID}'
,'{$originalName}'
,'{$clientRef}'
,'{$order}'
,'{$galleryLayout}'
)";
$return = mysql_query($query);
$ ORIGINALNAME是$變量,我需要將其定義爲img.jpg,$ IMG(1).JPG等我只是發表文件,它最終成爲了來自輸入的原始選定文件。
這是選擇文件的格式。
<form class="fileupload" id="albumBack" action="../js/jQuery-file-upload/server/php/" method="POST" enctype="multipart/form-data" >
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
<div class="row fileupload-buttonbar">
<span class="btn btn-success fileinput-button">
<span>Choose Back</span>
<input type="file" name="files[]">
</span>
</div>
這是你正在使用的整個腳本? –
js還是PHP類?還有更多的PHP類。至於js,是的,這是所有的腳本,我將編輯完整的 – Bungdaddy
作爲一邊;你應該真的使用PHP PDO:http://php.net/manual/en/book.pdo.php你目前很容易受到SQL注入攻擊。 –