Jump to content

uploading... very close, but not quite..


rnb_cassanova

Recommended Posts

Hi lads,

I am trying to create an upload script. I am using http://uk3.php.net/features.file-upload for advice; Although i am receiving errors. My code is as follows-

 

$uploaddir = '/DV8 System/Uploads/';  // im not sure if this is where the problem is - am i putting the directory in correctly?

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo $uploadfile;

echo '<pre>';

 

<form enctype="multipart/form-data" action="ValidatingUploadAdminForm.php" method="POST"> // also should this point to a form of to the upload directory?

 

Cheers in advance lads

 

David

Link to comment
Share on other sites

I dont know if this will help you but this is what I am using.

 

<?php

$TofD = $_POST["TofD"];

$target = "files/";

$target = $target . basename( $_FILES['uploaded']['name']) ;

$ok=1;

 

//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 =="text/php")

{

echo "No PHP files<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";

}

else

{

echo "Sorry, there was a problem uploading your file.";

}

}

?>

 

 

and I am calling it from this within the html

 

<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>

 

It works great. Also if anyone knows how to add list box or selction box to this and reroute the upload please see my thread...

 

Dennis

 

Link to comment
Share on other sites

Hi sorry,

 

DV8 System/Uploads/Dave.doc

 

 

 

Warning:  move_uploaded_file(DV8 System/Uploads/Dave.doc) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\DV8 System\ValidatingUploadAdminForm.php on line 9

 

 

 

Warning:  move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\phpE8A3.tmp' to 'DV8 System/Uploads/Dave.doc' in C:\wamp\www\DV8 System\ValidatingUploadAdminForm.php on line 9

 

Possible file upload attack!

Here is some more debugging info:Array

(

    [userfile] => Array

        (

            [name] => Dave.doc

            [type] => application/msword

            [tmp_name] => C:\wamp\tmp\phpE8A3.tmp

            [error] => 0

            => 28160

        )

 

)

 

the code is

 

 

[code

<!-- The data encoding type, enctype, MUST be specified as below -->

<form enctype="multipart/form-data" action="ValidatingUploadAdminForm.php" method="POST">

    <!-- MAX_FILE_SIZE must precede the file input field -->

    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />

    <!-- Name of input element determines name in $_FILES array -->

    Send this file: <input name="userfile" type="file" />

    <input type="submit" value="Send File" />

</form>

]

 

and

 

<?php

// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead

// of $_FILES.

 

$uploaddir = 'DV8 System/Uploads/';

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo $uploadfile;

echo '<pre>';

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {

    echo "File is valid, and was successfully uploaded.\n";

} else {

    echo "Possible file upload attack!\n";

}

 

echo 'Here is some more debugging info:';

print_r($_FILES);

 

print "</pre>";

 

?>

 

sorry its everywhere, if there is a better method of pasting this please let me know.

Cheers

 

David

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.