Hi, I'm creating a upload form for an open-source games track and kart repos. Basically I'm trying to code a upload form that allows user to select, from a pop-up menu, if they are uploading a kart or a track; then they select the file (File MUST be gziped or bziped). If they choose that the file is a kart, the file will be uploaded in ./karts,; if a track, it will be uploaded in ./tracks.
So I did some searching on the internet, and coded a basic outline for part of my upload form.
<
PS: The finished work will most likely be CC-BY
So I did some searching on the internet, and coded a basic outline for part of my upload form.
<
Code:
?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
//NOT CURRENTLY USED
//This is our size condition
//if ($uploaded_size > 350000)
//{
//echo "Your file is too large.<br>";
//$ok=0;
//}
//This is our limit file type condition
if (!($uploaded_type =="application/gzip" || $uploaded_type =="application/x-gzip"|| $uploaded_type =="application/x-bz2" || $uploaded_type =="application/x-bzip" || $uploaded_type =="application/bzip"))
{
echo "File MUST be gziped or bziped<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded,<br>it will be in the add--on manager shortly";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
Code:
<form enctype="multipart/form-data" action="upload.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form>
Comment