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
https://forums.phpfreaks.com/topic/94698-uploading-very-close-but-not-quite/
Share on other sites

Hi there,

 

i seem to be having a problem with a similar problem, im following this tutorial: http://www.phpriot.com/articles/images-in-mysql/5

 

I can get the image to upload Error Free No Problem, but to display the image...well i seem to be having problems in that nothing dynamic displays....

 

Thanks

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

 

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.