【问题标题】:Link two PHP upload forms?链接两个PHP上传表单?
【发布时间】:2011-08-05 15:27:18
【问题描述】:

我创建了两个单独的 PHP 表单。一个用于上传视频(因此它接受 .avi、.mp4、.ogv),然后另一个用于上传视频缩略图(因此它接受 .png、.jpeg)。有什么办法可以链接这些,以便在各自的文件夹或任何东西中以相同的名称创建它们?我可以让视频缩略图表单仅在视频提交后显示吗?谢谢。

这是 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),我们将帮助您将它们结合起来。只是说你想要什么和你有什么让我们不知道你的问题是什么
  • 编辑您的问题并添加该代码..

标签: php forms file-upload


【解决方案1】:

只需将缩略图输入到您的视频上传表单中,您就会同时收到两者

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    • 1970-01-01
    相关资源
    最近更新 更多