まず最初に、私はここに来たばかりなので、これを正しく投稿していない場合はお知らせください。このサイトで広範囲に検索しましたが、私の問題を正確に見つけることができませんでした。
フォームの名前フィールドの応答とアップロードの日付に従って、複数のファイルをアップロードし、ファイルの名前を変更する (元のファイル名に名前と日付を追加する) 必要がある php フォームとアップローダーがあります。
例外はすべて機能します。複数のファイルではなく、1 つのファイルのみがアップロードされます。私がこれを書いている間、それはうまくいきましたが、最近何かを台無しにしました。
誰かが私がどこで間違ったのか教えてもらえますか? ありがとう。
フォームのコードは次のとおりです。
<?php
// make a note of the current working directory relative to root.
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
// location of the upload handler
$uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.processor.php';
// max file bytes (2mb)
$max_file_size = 2097152;
// echo
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<title>Upload Your Awesome Images!</title>
</head>
<body>
<form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">
<span>Step #2</span>
<h1>
Upload Your Images!
</h1>
<div style="border:#999 1px solid;padding:5px">
<p>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
</p>
<p> Photographer's Name: <input type="text" name="photogname" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>"> </p>
<p>
<label for="file">File to upload:</label>
<input id="file" type="file" name="file[]" class="tag" multiple/>
</p>
<p>
<label for="submit">Press to...</label>
<input id="submit" type="submit" name="submit" value="Upload me!">
</p>
</div>
<p>Max file size= 2mb</p>
<p>Max number of files uploadable = 20</p>
<p>*Important Note: When submitting photos, please be sure that you are the owner of the images, or that you have explicit permission from the owner to use them. All copyrights will be verified before winners are announced. </p>
</form>
</body>
</html>
そして、ここに処理があります:
<?php
//current local
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
//locations/dirs
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . '../images/PhotoContest/';
$uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.form.php';
$uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.success.php';
$fieldname = 'file';
// upload
// possible upload errors (more?)
$errors = array(1 => 'php.ini max file size exceeded',
2 => 'html form max file size exceeded',
3 => 'file upload was only partial',
4 => 'no file was attached');
// check the upload form was actually used. no fancy injection stuff
isset($_POST['submit'])
or error('woah. you can\'t upload images without the form', $uploadForm);
// check for standard uploading errors
($_FILES[$fieldname]['error'] == 0)
or error($errors[$_FILES[$fieldname]['error']], $uploadForm);
// check that the file was an HTTP upload, not a sneaky pete
@is_uploaded_file($_FILES[$fieldname]['tmp_name'])
or error('not an HTTP upload', $uploadForm);
// validation...
// should run a check to make sure the upload is an image
@getimagesize($_FILES[$fieldname]['tmp_name'])
or error('only image uploads are allowed', $uploadForm);
//name this file. If not, name by time (remove time function when name works right)
$now = date('m-d-Y');
$photogname = ($_POST['photogname']);
while(file_exists($uploadFilename = $uploadsDirectory.$photogname.$now.'-'.$_FILES[$fieldname]['name']))
{
$now++;
}
// move the file to final dir (& check perm)
@move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
or error('receiving directory insuffiecient permission', $uploadForm);
// sucess
header('Location: ' . $uploadSuccess);
// error handler
function error($error, $location, $seconds = 5)
{
header("Refresh: $seconds; URL=\"$location\"");
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
'"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
'<html lang="en">'."\n".
' <head>'."\n".
' <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
' <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
' <title>Upload error</title>'."\n\n".
' </head>'."\n\n".
' <body>'."\n\n".
' <div id="Upload">'."\n\n".
' <h1>Upload failure</h1>'."\n\n".
' <p>An error has occured: '."\n\n".
' <span class="red">' . $error . '...</span>'."\n\n".
' The upload form is reloading</p>'."\n\n".
' </div>'."\n\n".
'</html>';
exit;
} // end error handler
?>