I don't know why but i had written clear cut code for uploading file in my page.
i had written like this... on the client side.
<form id="recipeform" onsubmit="return checkAll()" action="submit.php" method="post" class="niceform" enctype="multipart/form-data">
<input name="uploaded" type="file" />
And on submit.php... i am writting like this.....
$target = "newupload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){
echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
}
else{
开发者_如何学JAVA echo "Sorry, there was a problem uploading your file.";
}
simple code but then also i can't able to upload the file.. And i had made my webiste in Drupal.
Thanks in advance. www.panchjanyacorp.com
Have you checked the PHP and/or server error logs? Perhaps PHP's max upload size and/or an Apache-type LimitRequestBody is limiting upload file size and you're exceeding it.
You should also check the $_FILES['uploaded']['error'] value, which will contain the error code for the upload operation. Never assume that the upload succeeded... you should be doing at least the following:
if($_FILES['uploaded]['error'] === UPLOAD_ERR_OK) {
... handle upload here...
} else {
... handle error condition here ...
}
The full suite of error constants is defined here in the PHP docs.
Oh, and be aware that your code is vulnerable to filename collisions. You will be overwriting existing files if one with the same basename is uploaded. Perhaps this is what you intended, but just a friendly warning.
精彩评论