21.03.2014, 22:00
Okay, so I'm not all that good with PHP and was wondering how I'd get an action from a form.
For example, you can upload a MP4, PNG or a JPEG file.
so when they file uploads, I want to add "?action=success" to the url so the website knows to display the $success message.
But I'm not all that good with it, could someone help me out?
Form code:
PHP Code:
For example, you can upload a MP4, PNG or a JPEG file.
so when they file uploads, I want to add "?action=success" to the url so the website knows to display the $success message.
But I'm not all that good with it, could someone help me out?
Form code:
PHP код:
<div class="container">
<center>
<h3>Upload your file:</h3>
<form action="home.php?action=" method="POST" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" name="submit" value="Upload">
</form>
</center>
</div>
PHP код:
if(isset($_POST['submit']))
{
$name = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
$type = $_FILES['file']['type'];
$size = $_FILES['file']['size'];
$url = "localhost/video%20host/uploaded/$name";
$error = "<div class='alert alert-danger'>There was an error uploading your file. Supported files are: MP4 - Jpeg - PNG</div>";
$success = "<div class='alert alert-success'>File uploaded successfully. <br />Link:<br/>$url</div>";
if(($_FILES["file"]["type"] == "video/mp4") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png"))
{
move_uploaded_file($temp,"uploaded/".$name);
mysql_query("INSERT INTO `videos` VALUE('', '$name', $url')");
}
}