<?php

if (isset($_POST['submited']))
{

if (isset($_FILES['upload']))
{

$allowed=array('image/JPEG','application/x-bittorrrent');
if (in_array($_FILES['upload']['type'],$allowed))
{
if(move_uploaded_file($_FILES['upload']['tmp_name'] , "../upload/$_FILES['upload']['tmp_name']"))
{
echo'Your file has been successfully uploaded!';
}
else 
{
echo'Please upload a torrent file!';
}

}


}

if ($_FILES['upload']['error']>0){echo 'An error has occured.';}
if (file_exists ($_FILES['upload']['tmp_name']) 

&& is_file( $_FILES['upload']['tmp_name'] ) ){
unlink ($_FILES['upload']['tmp_name'] );
}
}
?>




<html>
<title>Upload</title>
<body>
<form enctype="multipart/form-data" action="upload_torrent.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="50000000"/>
<input type="file" name="upload"/>
<input type="submit" name="submit" value="submit"/>
<input type="hidden" name="submitted" value="TRUE" />
</form>
</body>
</html>

Here is my upload form and php upload script. I am using an example from Visual QuickPro Guide PHP 6 and MySQL 5. I changed it just a little bit to allow torrents. I kept the jepg though to see if it works with regular files. No errors, yet no upload. I don't see anything particularly that sticks out, and I am booting from a zwamp environment. I am also using Windows 8. I edited any errors with the form I believe, but I don't see what could be causing a problem. Thanks!

try this. its also validated

<?php
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["upload"]["name"]);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

    $check = getimagesize($_FILES["upload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }


// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["upload"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["upload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["upload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
}
?>

This is what I got.

File is an image - image/jpeg.
Warning: move_uploaded_file(uploads/pookie.jpg): failed to open stream: No such file or directory in Z:\web\upload_torrent.php on line 37

Warning: move_uploaded_file(): Unable to move 'Z:\.tmp\phpD868.tmp' to 'uploads/pookie.jpg' in Z:\web\upload_torrent.php on line 37
Sorry, there was an error uploading your file.

Is the picture just screwed up? I am kind of confused.

Sorry, didn't notice that *upload was turned to *uploads

So why didn't the previous script work? File path? Or it needed validated?

your error lies in line 10

if (in_array($_FILES['upload']['type'],$allowed)

should be validating the file type but your not getting the .gif .png .jpg

it should be like this to get the file type then validate this file extension
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

this is the validation of that file extension

  if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
    && $imageFileType != "gif" ) {
        echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
        $uploadOk = 0;
    }

if the problem is solve please click solve if you have anymore question dont hesitate to ask

Could it be because I threw in torrents as well? Perhaps that is what killed it. Still thank you!

using torrent I think you will use API on that torrent file.this is not so much on PHP side of uploading its different

also i dont know about uploading/downloading torrents in php much but i think it this link will help you.

note that link is just a search from google i dont know much about it sorry.

Thanks. I just figured to upload a torrent, you upload it like anything else (.exe, jpeg, etc.). I only found one link and it basically said to put 'application/x-bittorrent' as the thing. Must have been wrong. Any how thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.