文件上传阿贾克斯PHP [英] File Upload Ajax PHP
问题描述
我有一段使用Ajax和PHP上传图片的JavaScript。
I have a piece of javascript that uses Ajax and PHP to upload an image.
我正在使用的一些html页面的头部的JavaScript,想知道是否有从这些页面到upload.php的文件传递价值的一种方式,而无需创建单独的upload.php的文件,每个网页
I am using the javascript in the head section of a few html pages and was wondering if there was a way of passing a value from these pages to the Upload.php file, without having to create individual Upload.php files for each web page.
的JavaScript的部分:
Section of the javascript:
<script type="text/javascript" >
$(function(){
var btnUpload=$('#me');
var mestatus=$('#mestatus');
var files=$('#files');
new AjaxUpload(btnUpload, {
action: '../UploadDoc/Upload.php',
name: 'uploadfile',
在upload.php的文件的部分我想传递值:
Section of the Upload.php file i would like to pass value to:
<?php
/* Set the location to upload the file to */
$uploaddir = '../documents/userdocs/';
/* Set the name and file extension of the file being saved */
$file = $uploaddir ."HtmlPage1_".basename($_FILES['uploadfile']['name']);
$file_name= "HtmlPage1_".$_FILES['uploadfile']['name'];
在哪里HtmlPage1_'将是我需要传递的,因为它是唯一改变的部分信息。
Where 'HtmlPage1_' will be the information i need to pass in, as it is the only part that changes.
任何帮助非常AP preciated。
Any help much appreciated.
感谢
推荐答案
在你的Javascript做
In your Javascript do
$(function(){
var btnUpload=$('#me');
var mestatus=$('#mestatus');
var files=$('#files');
new AjaxUpload(btnUpload, {
action: '../UploadDoc/Upload.php',
name: 'uploadfile',
params: {
pageKey: 'HtmlPage1_'
}
......ETC-CODE......................
或你的JavaScript code执行
OR your javascript code do
$(function(){
var btnUpload=$('#me');
var mestatus=$('#mestatus');
var files=$('#files');
new AjaxUpload(btnUpload, {
action: '../UploadDoc/Upload.php?pageKey=HtmlPage1_',
name: 'uploadfile',
......ETC-CODE......................
和你的PHP做的:
<?php
/* Set the location to upload the file to */
$uploaddir = '../documents/userdocs/';
/* Set the name and file extension of the file being saved */
$file = $uploaddir .$_REQUEST['pageKey'].basename($_FILES['uploadfile']['name']);
$file_name= $_REQUEST['pageKey'].$_FILES['uploadfile']['name'];
......ETC-CODE......................
然后修改你的JavaScript code在每个页面一个pageKey参数。
Then you modify your javascript code in each page to a "pageKey" parameter.
这篇关于文件上传阿贾克斯PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!