0
我創建了兩個獨立的PHP表單..一個上傳視頻(所以它接受.avi,.mp4,.ogv),然後另一個上傳視頻縮略圖(所以它接受.png,.jpeg)。有什麼辦法可以將它們鏈接起來,以便它們在相應的文件夾或其他文件夾下以相同的名稱創建?我可以讓視頻縮略圖表單隻在視頻提交後顯示嗎?謝謝。鏈接兩個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