0
私は2つの別々のPHPフォームを作成しました.1つはビデオをアップロードするため(.avi、.mp4、.ogvを受け付けるように)、もう1つはビデオサムネイルをアップロードするためです(したがって、.png、.jpegを受け入れます)。これらをリンクして、それぞれのフォルダや同じ名前で同じ名前で作成する方法はありますか?また、ビデオサムネイルフォームは、ビデオが提出された後にのみ表示されるようにすることはできますか?ありがとう。ここで 2つのPHPアップロードフォームをリンクしますか?
はPHPです:<?php
define ('MAX_FILE_SIZE', 220200960); //define a constant for the maximum upload size (200 MB)
if (array_key_exists('uploadvideo', $_POST)) {
define('UPLOAD_DIR', 'videos/'); // define constant for upload folder
$file = str_replace(' ', '_', $_FILES['video']['name']); //replace any spaces with underscores, and at the same time assign to a simpler variable
$max = number_format(MAX_FILE_SIZE/1048576, 210). 'MB'; //convert the maximum size to MB
$permitted = array('video/x-msvideo','video/mp4','application/ogg');
$sizeOK = false; //begin by assuming the file is unacceptable
$typeOK = false;
if ($_FILES['video']['size'] > 0 && $_FILES['video']['size'] <= MAX_FILE_SIZE) {
$sizeOK = true;
} //check that file is within the permitted size
foreach ($permitted as $type) {
if ($type == $_FILES['video']['type']) {
$typeOK = true;
break;
}
}
if ($sizeOK && $typeOK) {
switch($_FILES['video']['error']) {
case 0: //move the file to the upload folder and rename it
$success = move_uploaded_file($_FILES['video']['tmp_name'], UPLOAD_DIR.$file);
if ($success) {
$result ="$file uploaded successfully";
}
else {
$result = "Error uploading $file. Please try again.";
}
break;
case 3:
$result = "Error uploading $file. Please try again.";
default:
$result = "Sysstem error uploading $file. Contact webmaster.";
}
}
elseif ($_FILES['video']['error'] == 4) {
$result = 'No file selected';
}
else {
$result = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: .avi, .mp4, .ogv.";
}
}
?>
<?php
define ('MAX_FILE_SIZE', 10485760); //define a constant for the maximum upload size (200 MB)
if (array_key_exists('uploadthumb', $_POST)) {
define('UPLOAD_DIR', 'thumbs/'); // define constant for upload folder
$file = str_replace(' ', '_', $_FILES['thumb']['name']); //replace any spaces with underscores, and at the same time assign to a simpler variable
$max = number_format(MAX_FILE_SIZE/1048576, 10). 'MB'; //convert the maximum size to MB
$permittedthumb = array('image/jpeg','image/pjpeg','image/png', 'image/x-png');
$sizeOK = false; //begin by assuming the file is unacceptable
$typeOK = false;
if ($_FILES['thumb']['size'] > 0 && $_FILES['thumb']['size'] <= MAX_FILE_SIZE) {
$sizeOK = true;
} //check that file is within the permitted size
foreach ($permittedthumb as $type) {
if ($type == $_FILES['thumb']['type']) {
$typeOK = true;
break;
}
}
if ($sizeOK && $typeOK) {
switch($_FILES['thumb']['error']) {
case 0: //move the file to the upload folder and rename it
$successthumb = move_uploaded_file($_FILES['thumb']['tmp_name'], UPLOAD_DIR.$file);
if ($successthumb) {
$resultthumb ="$file uploaded successfully";
}
else {
$resultthumb = "Error uploading $file. Please try again.";
}
break;
case 3:
$resultthumb = "Error uploading $file. Please try again.";
default:
$resultthumb = "Sysstem error uploading $file. Contact webmaster.";
}
}
elseif ($_FILES['thumb']['error'] == 4) {
$resultthumb = 'No file selected';
}
else {
$resultthumb = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: .avi, .mp4, .ogv.";
}
}
?>
そして、ここではHTMLです:
<h3 class="titlehdrblue">Upload Video</h3>
<br></br>
<?php
if (isset($result)) {
echo "<p><strong>$result</strong></p><br></br>";
}
?>
<form action="" method="post" enctype="multipart/form-data" name="uploadVideo" id="uploadVideo">
<p>
<label for ="video">Upload video:</label>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />
<input type="file" name="video" id="video" />
</p>
<br></br>
<p>
<input type="submit" name="uploadvideo" id="uploadvideo" value="Upload Video" />
</p>
</form>
<br></br>
<br></br>
<h3 class="titlehdrblue">Upload Video Thumbnail</h3>
<br></br>
<?php
if (isset($resultthumb)) {
echo "<p><strong>$resultthumb</strong></p><br></br>";
}
?>
<form action="" method="post" enctype="multipart/form-data" name="uploadThumb" id="uploadThumb">
<p>
<label for ="thumb">Upload thumbnail:</label>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />
<input type="file" name="thumb" id="thumb" />
</p>
<br></br>
<p>
<input type="submit" name="uploadthumb" id="uploadthumb" value="Upload Thumbnail" />
</p>
</form>
あなたの現在のコードと(HTMLとPHPの両方)を私たちに教えてください。それらを組み合わせることをお手伝いします。ちょうどあなたが何を望んでいるのか、あなたが持っているものはあなたの問題が本当に何の問題かわかりません –
あなたの質問を編集し、そのコードを追加してください。 –
申し訳ありません、コードが追加されました – Jakemmarsh