Note that there are some explanatory texts on larger screens.

plurals
  1. POLink two PHP upload forms?
    primarykey
    data
    text
    <p>I have created two separate PHP forms.. One to upload a video (so it accepts .avi, .mp4, .ogv), and then another to upload the video thumbnail (so it accepts .png, .jpeg). Is there any way I can link these so that they are created under the same name in their respective folders or anything? And can I make the video thumbnail form only show up after the video one has been submitted? Thanks.</p> <p>Here's the PHP:</p> <pre><code>&lt;?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'] &gt; 0 &amp;&amp; $_FILES['video']['size'] &lt;= 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 &amp;&amp; $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."; } } ?&gt; &lt;?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'] &gt; 0 &amp;&amp; $_FILES['thumb']['size'] &lt;= 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 &amp;&amp; $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."; } } ?&gt; </code></pre> <p>And here's the HTML:</p> <pre><code>&lt;h3 class="titlehdrblue"&gt;Upload Video&lt;/h3&gt; &lt;br&gt;&lt;/br&gt; &lt;?php if (isset($result)) { echo "&lt;p&gt;&lt;strong&gt;$result&lt;/strong&gt;&lt;/p&gt;&lt;br&gt;&lt;/br&gt;"; } ?&gt; &lt;form action="" method="post" enctype="multipart/form-data" name="uploadVideo" id="uploadVideo"&gt; &lt;p&gt; &lt;label for ="video"&gt;Upload video:&lt;/label&gt; &lt;input type="hidden" name="MAX_FILE_SIZE" value="&lt;?php echo MAX_FILE_SIZE; ?&gt;" /&gt; &lt;input type="file" name="video" id="video" /&gt; &lt;/p&gt; &lt;br&gt;&lt;/br&gt; &lt;p&gt; &lt;input type="submit" name="uploadvideo" id="uploadvideo" value="Upload Video" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;br&gt;&lt;/br&gt; &lt;br&gt;&lt;/br&gt; &lt;h3 class="titlehdrblue"&gt;Upload Video Thumbnail&lt;/h3&gt; &lt;br&gt;&lt;/br&gt; &lt;?php if (isset($resultthumb)) { echo "&lt;p&gt;&lt;strong&gt;$resultthumb&lt;/strong&gt;&lt;/p&gt;&lt;br&gt;&lt;/br&gt;"; } ?&gt; &lt;form action="" method="post" enctype="multipart/form-data" name="uploadThumb" id="uploadThumb"&gt; &lt;p&gt; &lt;label for ="thumb"&gt;Upload thumbnail:&lt;/label&gt; &lt;input type="hidden" name="MAX_FILE_SIZE" value="&lt;?php echo MAX_FILE_SIZE; ?&gt;" /&gt; &lt;input type="file" name="thumb" id="thumb" /&gt; &lt;/p&gt; &lt;br&gt;&lt;/br&gt; &lt;p&gt; &lt;input type="submit" name="uploadthumb" id="uploadthumb" value="Upload Thumbnail" /&gt; &lt;/p&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload