问题描述
嘿,我在看uploadify.php 并没有理解一件事.
Hy , i was looking at uploadify.php and did'n understand a thing.
我有一个这样的表格:
<form id="formid" name="upload_pic" action="upload.php">
<select name="product_id">
<option value="1">Apples</option>
<option value="2">Oranges</option>
... etc
</select>
<input id="file_upload" name="file_upload" />
</form>
我的uploadify设置是:
and my uploadify settings are :
<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : 'uploadify/uploadify.swf',
'script' : 'uploadify/uploadify.php',
'cancelImg' : 'uploadify/cancel.png',
'folder' : '../images/level3/tabv_all/tab_header/',
'auto' : false,
'multi' : true,
'fileExt' : '*.jpg',
'fileDesc' : 'ONLY JPG (.JPG)',
'removeCompleted' : false
});
});
</script>
我想要做的是,如果用户选择具有 id=1
的 Apples
和 浏览像 Tasty_apples.jpg 之类的文件
-> 上传的文件要重命名为 product@1@Tasty_apples.jpg
然后像这样插入到 mysql 中?
What i want to do is that if the user select Apples
wich has the id=1
and browse for a file like Tasty_apples.jpg
-> the uploaded file to be renames to product@1@Tasty_apples.jpg
and then to be inserted in mysql like that?
主要问题是如何基于 将额外的
?product@id@
添加到文件中.价值
The main question is how to add the extra product@id@
to a file based on a <select><option> value
?
非常感谢
uploadify.php 是这样的:
The uploadify.php is this :
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
}
推荐答案
您可以使用 scriptData 选项向后端脚本发送额外数据:
You can send additional data to your backend script with scriptData option:
http://www.uploadify.com/documentation/options/scriptdata/
例子
var selectedID = $("select[name=product_id]").val()
'scriptData' : {'pid': selectedID}
// uplodify.php
$targetFile = str_replace('//','/',$targetPath) . 'product@' . $_POST['pid'] . '@' . $_FILES['Filedata']['name'];
这篇关于uploadify - 重命名上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!