我正在开发一个项目,该项目将采用独立的PHP应用程序并将其移至WordPress。我已经做到了,现在在WordPress中,我正在为足球运动员制定一个特定的注册顺序,以将自己注册为团队的球员。在序列中的某个时刻,用户上传了自己的图像。在代码中,是文件“ select-image.php”,然后试图检索“ upload-image.php”和“ edit-image.php”,但分别返回错误代码301和302。
我附上了一个截图,其中显示了尝试检索upload-image.php和edit-image.php时的网络活动。两种资源均未永久移动。我还附加了一个屏幕截图,其中显示了该文件实际上应该在服务器上的位置。
'select-image.php'
<?php
require_once $_SERVER ['DOCUMENT_ROOT'] . '/required-php-db-connect.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/session-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/ACS-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/org-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/constants-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/cart-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/division-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/team-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/user-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/form-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/image-library.php';
// request page post variables here, ensure that '/libraries/form-library.php' is required above
$return_page = "";
if(!empty($_POST["return_page"])){
$return_page = $_POST["return_page"];
}
// pre-header php functions (such as ACS activities)
$return_page = "";
if(!empty($_POST["return_page"])){
$return_page = $_POST["return_page"];
}
$image_mode = get_session_value('image_mode');
if ($image_mode == "") {
$image_mode = optional_form_item('image_mode');
}
if ($image_mode == 'cart_image_mode'){
$debug_mode = get_session_value('debug_mode');
$debug_string = "";
$transaction_id = get_session_value('transaction_id');
$user_cart = new Cart();
$user_cart->load_cart($transaction_id);
$cart_user_info = new cart_user_info();
$cart_user_info->load_cart_user_info_by_transaction_id($transaction_id);
$user_id = $cart_user_info->get_cart_user_info_user_id();
} else {
$user_id = optional_form_item('user_id');
$team_id = optional_form_item('team_id');
set_session_value('edit_team_id',$team_id);
}
set_session_value('image_edit_user_id', $user_id);
// load jquery libraries
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/jquery-link-library.php';
// load common css libraries
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/css-link-library.php';
$age_level = get_session_value('age_level');
if($age_level == 'youth') {
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/bootstrap-library.php';
}
//get default season
$this_season = new Season();
$season_text = $this_season->display_current_soccer_year();
$error_message = get_session_value('error_message');
set_session_value('error_message', null);
// load page specific css libraries
//require once $_SERVER['document_root'].'/libraries/roster.css';
?>
<!-- all local style references go here. USE SPARINGLY! -->
<style type=text/css>
.inactive_step {
font-weight: normal;
border:thin #000000 solid;
display:inline-block;
}
.active_step {
font-weight: bold;
border: thin #FF0000 solid;
display:inline-block;
}
</style>
</head>
<body id='body'>
<div class="wrapper">
<!-- location of libraries that display data to the page, in the order that the data is displayed -->
<?php if($age_level == 'youth') { require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/new-menu-bar.php'; } else { require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/menu-bar.php'; } ?>
<?php require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/admin-header.php'; ?>
<div class="main_body">
<!-- place all content here -->
<?php
if($age_level == 'youth'){
echo '<div class="jumbotron" style="margin: auto;">';
}
//$image_path = determine_user_image_path($user_id) . "/". get_user_image_file_name($user_id);
$image_path = get_image_database_path_and_name($user_id);
//1:
//place ACS and id user info here
//$user_id = get_cart_session_id();
if (empty($error_text)){
//create page output here
} else {
$display_data = $error_text;
}
?>
<font style="font-size: 18pt; color: red; align: center;"><?php echo $error_message; ?></font>
<table align="center" cellspacing="0" cellpadding ="0" width="1000" style="border: solid black 2px; align-self: center; margin: auto;">
<?php
if ($image_mode == 'cart_image_mode' && $age_level != 'youth'){
echo '<tr style = "border-bottom: solid black 2px;">';
echo '<td colspan="2" width="1000" align="center">';
display_progress(3);
echo "</td> </tr>";
} else if($image_mode == 'cart_image_mode' && $age_level == 'youth') {
echo '<tr>
<td colspan=2>
<h1>Youth Player Registration</h1>
<h3>' . trim($season_text) . '</h3>
</td>
</tr>
<tr>
<td colspan="2" width="970" align="center">';
display_new_progress(5);
echo "</td> </tr>";
}
?>
<tr>
<td valign="top" colspan =2 align= 'center' style = "font-size: 18px;"> <!-- BOTH sides of box -->
<table cellspacing=0 cellpadding=3 border=0 width=1000 align='center' >
<tr>
<td colspan="2" align="left" style="padding-left: 10px;">
<br />
Click <strong>Browse</strong> to upload your picture or take a picture with your cell phone.
<br />
<br />
Please select a picture that clearly shows your face.
<br /><br />
A small camera picture works MUCH better than a facebook picture. You will have a chance to rotate and crop the picture to select just your face. If you cannot get a picture to load correctly, it is probably too large in size or dimension. Use a smaller picture.
<br /> <br />
You MUST click on the box, shown below on the left (Current Picture), at least once for your picture to show up correctly.<br /><br /> Once you find the file or select your picture, click <strong>Upload Picture</strong>.
<br />
<br />
</td>
</tr>
<tr >
<td align="center">
<font style="font-size:16px;">Current Picture</font>
<br>
<img src="<?php echo $image_path; ?>" height="200px;" width="200px;"><br />
<br />
</td>
<td align="center" >
<br />
<form enctype="multipart/form-data" method="post" id="select_image_form" action="/images/upload-image.php" style='font-size: 18px;'>
<div class="row">
<label for="fileToUpload" style='font-size: 18px;'></label>
<button style='height: 70px; width: 250px; font-size:18px;' onclick="document.getElementById('fileToUpload').click();">Click here to select a file or take a pic with your phone</button>
<div style='height: 0px;width: 0px; overflow:hidden;'>
<input type="file" accept="capture=camera" name="fileToUpload" id="fileToUpload" style='font-size: 18px;' onchange="var x = document.getElementById('fileToUpload').value;document.getElementById('file_display').value = x; "/>
</div><br />
File to upload: <input type=text id="file_display" ></input>
<input type="hidden" name = "user_id" value = "<?php echo $user_id ?>">
<input type="hidden" name = "return_page" value = "<?php echo $return_page ?>">
</div>
<div class="row">
<br />
<input type="submit" style='font-size: 18px;' value="Upload This Picture" />
</div>
</form>
<br>
<form action="/images/edit-image-action.php" method="post">
<input type = 'hidden' name = 'image_action' value = 'save_old' />
<input type='hidden' name='old_path' value = '<?php echo $image_path; ?>' />
<input type="submit" style='font-size: 18px;' value="Keep the Current Pic and Skip This Step">
</form>
</td>
</tr>
</table><br />
<!-- Add in javascript based 'press button once' feature -->
</td>
</tr>
</table>
</div> <!-- end of main content area -->
<?php require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/user-footer.php'; ?>
</div> <!-- end of wrapper -->
</body>
</html>
<script type="text/javascript">
$( "#select_image_form" ).validate({
rules: {
fileToUpload: {
required: true,
accept: "image/*"
}
},
messages: {
fileToUpload:{
required: "You must select a picture to continue",
accept: "You must select an Image File."
}
}
});
</script>
'upload-image.php'
<?php
require_once $_SERVER ['DOCUMENT_ROOT'] . '/required-php-db-connect.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/session-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/ACS-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/user-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/cart-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/image-library.php';
$debug_mode = get_session_value('debug_mode');
$debug_string = "";
$debug_string .= "<br/> Debug Mode: $debug_mode";
$redirect_url = "/images/edit-image.php";
//set memory limit to accomodate uploading of 8MB images -TF
ini_set("memory_limit", "512M");
//$user_id = get_cart_session_id();
$image_mode = get_session_value('image_mode');
if ($image_mode == 'admin_image_mode'){
$user_id = get_session_value('image_edit_user_id');
}else {
$transaction_id = get_session_value('transaction_id');
$cart_user_info = new Cart_user_info();
$cart_user_info->load_cart_user_info_by_transaction_id($transaction_id);
$user_id = $cart_user_info->get_cart_user_info_user_id();
}
if ($_FILES['fileToUpload']['error'] > 0) {
$debug_string .= UploadException($_FILES['fileToUpload']['error']);
} else {
// array of valid extensions
$validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
// get extension of the uploaded file
$fileExtension = strtolower(strrchr($_FILES['fileToUpload']['name'], "."));
// check if file Extension is on the list of allowed ones
if (in_array($fileExtension, $validExtensions)) {
// we are renaming the file so we can upload files with the same name
// we simply put current timestamp in front of the file name
$newName = time() . '_' . $_FILES['fileToUpload']['name'];
$destination = '/images/temp/' . $newName;
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], 'c:/inetpub/wwwroot'.$destination)) {
$manipulator = new ImageManipulator();
$manipulator->setImageFile($_SERVER[ 'DOCUMENT_ROOT' ] . $destination);
$manipulator->rotate('360');
// rotate 360 degrees
//$newImage = rotateImage($image, 360);
//$manipulator->setImageResource($newImage);
$manipulator->save($_SERVER[ 'DOCUMENT_ROOT' ] . $destination);
//redirect_post($redirect_url, 'destination', $destination);
set_session_value("destination",$destination);
//header('Location: ' . $redirect_url);
}
} else {
$debug_string .= " <br/>You must upload an image...<br/> If the file you attempted to upload was an image, it may not be compatible with this system. Please try again with another file.";
}
}
?>
<html>
<head>
<title>save a picture</title>
<!-- all stylesheets go here -->
<link rel="stylesheet" href="/CSS/login.css" type="text/css" />
<link rel="stylesheet" href="/CSS/menu.css" type="text/css" />
<link rel="stylesheet" href="/CSS/common.css" type="text/css" />
<link rel="stylesheet" href="/images/demos.css" type="text/css" />
<link rel="stylesheet" href="/images/jquery.Jcrop.css" type="text/css" />
</head>
<body style="text-align:center;">
<div class="wrapper">
<!-- location of libraries that display data to the page, in the order that the data is displayed -->
<?php require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/logo-header.php'; ?>
<?php require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/menu-bar.php'; ?>
<?php require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/admin-header.php'; ?>
<div class="main_body">
<!-- place all content here -->
<?php
$next_page = $redirect_url;
$debug_string .= "<br/> Next page: $next_page";
$debug_string .= "<br/> Debug Mode: $debug_mode";
echo $debug_string;
upload_image_button($user_id);
header("location: $next_page");
continue_or_debug($next_page, $debug_mode);
?>
</div>
</div>
</body>
</html>
如果您需要'edit-image.php',我可以将其发布。
我不明白为什么错误提示资源'upload-image.php'很明显地位于需要放置的目录中而已被永久移动?
有什么作用? 谢谢, CM