iUnknown
22-03-2008, 11:53 PM
Hello,
I'm trying to make an uploader that when you upload a file, it uploads it to a directory (the path contains a variable but i don't think that's a problem). So anyway, that bit is straight forward. But then I want it to post something, to do with the file it's just uploaded. I want it to post a path, then the file that was just uploaded's name name. So, here is my code:
The form:
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>The code found on uploader.php:
<?
// Where the file is going to be placed
$target_path = "/home/shoutcas/public_html/autodj/". $valid_user ."/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
$target_path = "/home/shoutcas/public_html/autodj/". $valid_user ."/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
if($_SERVER['REQUEST_METHOD'] != "GET")
{
$filename = $_FILES['uploadedfile']['name'];
$fd = fopen("/home/shoutcas/public_html/autodj/". $valid_user ."/playlist.lst","w");
fwrite($fd, "/home/shoutcas/public_html/autodj/". $valid_user ."/". $filename ." |\n");
}
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded and added to the playlist.";
} else{
echo "There was an error uploading the file, please try again!";
}
?>Now, when I upload a file, it always gives me the "else" part (aka the error and it's failed).
Can anybody spot anything that's wrong?
Thanks in advance, I will give +rep of course. I may be having a few more posts, if I see you continuing to contribute to help me with problems I will be giving a gift in £ or HCs. :)
I'm trying to make an uploader that when you upload a file, it uploads it to a directory (the path contains a variable but i don't think that's a problem). So anyway, that bit is straight forward. But then I want it to post something, to do with the file it's just uploaded. I want it to post a path, then the file that was just uploaded's name name. So, here is my code:
The form:
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>The code found on uploader.php:
<?
// Where the file is going to be placed
$target_path = "/home/shoutcas/public_html/autodj/". $valid_user ."/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
$target_path = "/home/shoutcas/public_html/autodj/". $valid_user ."/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
if($_SERVER['REQUEST_METHOD'] != "GET")
{
$filename = $_FILES['uploadedfile']['name'];
$fd = fopen("/home/shoutcas/public_html/autodj/". $valid_user ."/playlist.lst","w");
fwrite($fd, "/home/shoutcas/public_html/autodj/". $valid_user ."/". $filename ." |\n");
}
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded and added to the playlist.";
} else{
echo "There was an error uploading the file, please try again!";
}
?>Now, when I upload a file, it always gives me the "else" part (aka the error and it's failed).
Can anybody spot anything that's wrong?
Thanks in advance, I will give +rep of course. I may be having a few more posts, if I see you continuing to contribute to help me with problems I will be giving a gift in £ or HCs. :)