我需要一些有关 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}
});
});
});
我当前获得的文件名是原始名称,而不是附加名称。感谢您对此的任何帮助。
专辑页面.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 等的 $variable。我只是 POSTING 文件,它最终是从输入中选择的原始文件。
这是选择文件的表格。
<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>