| |
|
Welcome to AstaHost - Dear Guest | |
Replying to Php File Upload
Topic Summary
kelvinmaki
Posted 21 August 2007 - 03:07 PM
You're welcome. Glad it helped.. 
Supa Comix
Posted 21 August 2007 - 02:37 PM
Awesome. Thanks dude i tried that stuff and it now works! Thanks a lot! 
kelvinmaki
Posted 21 August 2007 - 01:17 PM
Firstly, maybe you could point out what is the error you are getting. From these codes below,
It seems to be alright. Of course I assume that the variable $user and $fid is declared somewhere.
Secondly, as for the codes that really does the uploading,
If you are going to upload to folder uploads/, then you need to allow permission to write to that folder. Do a chmod for that folder. Did an upload once and found out that its due to permission, it prevent any files from writing to that directory. And of course before all this, you need to mkdir that directory.
There's once I encounter blank page after uploading the files. It didn't show any errors and just blank. This can be caused by trying to upload a huge filesize. If you are running this on localhost, then it should be fine. But if you want to upload a huge file to the server (eg. web hosting), you will need to set the memory limit in the php setup configuration to a higher value. That you can contact the administrator of the web hosting. However, there's another alternative to this approach. You can set the .htaccess file as well
Put the above line to your .htaccess at the root. This method solve for me.
By the way, these are all the problem I encounter for uploading a file. If you encounter the same problem, this might help abit. If not, tell us your error in details. What did you do that got the error and what is the error message.
Cheers
<form enctype="multipart/form-data" action="fileupload.php?op=up&user=<?php echo($user); ?>&fid=<?php echo($fid); ?>" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000000" /> Choose a file to upload: <input name="uploaded" type="file" id="uploaded" /> <input type="submit" value="Upload File" /> </form>
It seems to be alright. Of course I assume that the variable $user and $fid is declared somewhere.
Secondly, as for the codes that really does the uploading,
if ($op == "up"){
$target = "uploads/";
$target = $target . basename($_FILES['uploaded']['name']);
echo($target);
if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo("The file ") . basename ($_FILES['uploadedfile']['name']). "has been uploaded!";
$filesize = $uploaded_size;
$sql = mysql_query("UPDATE tbl_files SET filesize='$filesize' WHERE fileid='$fid'");
}
else {
echo ("Sorry, there was a problem uploading your file.");
}
}If you are going to upload to folder uploads/, then you need to allow permission to write to that folder. Do a chmod for that folder. Did an upload once and found out that its due to permission, it prevent any files from writing to that directory. And of course before all this, you need to mkdir that directory.
There's once I encounter blank page after uploading the files. It didn't show any errors and just blank. This can be caused by trying to upload a huge filesize. If you are running this on localhost, then it should be fine. But if you want to upload a huge file to the server (eg. web hosting), you will need to set the memory limit in the php setup configuration to a higher value. That you can contact the administrator of the web hosting. However, there's another alternative to this approach. You can set the .htaccess file as well
<FilesMatch "\.(php|html?)$"> php_value memory_limit 32M </FilesMatch>
Put the above line to your .htaccess at the root. This method solve for me.
By the way, these are all the problem I encounter for uploading a file. If you encounter the same problem, this might help abit. If not, tell us your error in details. What did you do that got the error and what is the error message.
Cheers
Supa Comix
Posted 21 August 2007 - 11:19 AM
Right i have done a check for a tutorial on this as well as a question about it but php is not allowed in the search box. So i thought i'd just ask what i want to know.
I have a form which uploads a file, it refreshes the page, uploads the file and then alerts the user to if the file has uploaded. To be honest im not sure why i keep getting the error. But here is the code:
This is the form that is used for the user to select the file
[codebox]<form enctype="multipart/form-data" action="fileupload.php?op=up&user=<?php echo($user); ?>&fid=<?php echo($fid); ?>" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
Choose a file to upload:
<input name="uploaded" type="file" id="uploaded" />
<input type="submit" value="Upload File" />
</form>[/codebox]
This is the upload code
[codebox]if ($op == "up"){
$target = "uploads/";
$target = $target . basename($_FILES['uploaded']['name']);
echo($target);
if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo("The file ") . basename ($_FILES['uploadedfile']['name']). "has been uploaded!";
$filesize = $uploaded_size;
$sql = mysql_query("UPDATE tbl_files SET filesize='$filesize' WHERE fileid='$fid'");
}
else {
echo ("Sorry, there was a problem uploading your file.");
}
}[/codebox]
If you could point out any problems with it please do.
I have a form which uploads a file, it refreshes the page, uploads the file and then alerts the user to if the file has uploaded. To be honest im not sure why i keep getting the error. But here is the code:
This is the form that is used for the user to select the file
[codebox]<form enctype="multipart/form-data" action="fileupload.php?op=up&user=<?php echo($user); ?>&fid=<?php echo($fid); ?>" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
Choose a file to upload:
<input name="uploaded" type="file" id="uploaded" />
<input type="submit" value="Upload File" />
</form>[/codebox]
This is the upload code
[codebox]if ($op == "up"){
$target = "uploads/";
$target = $target . basename($_FILES['uploaded']['name']);
echo($target);
if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo("The file ") . basename ($_FILES['uploadedfile']['name']). "has been uploaded!";
$filesize = $uploaded_size;
$sql = mysql_query("UPDATE tbl_files SET filesize='$filesize' WHERE fileid='$fid'");
}
else {
echo ("Sorry, there was a problem uploading your file.");
}
}[/codebox]
If you could point out any problems with it please do.



