A little help with php please |
Author: |
Message: |
Nathan
Veteran Member
    

Yeah, "large dimensions" ;)
Posts: 2978 Reputation: 76
– / / 
Joined: Apr 2005
|
O.P. A little help with php please
Ok guys,
I have coded a File upload system with a password Here
and it will not upload the file here is the code:
code: <?php
$status = $_GET['upload'];
if ($status=='1')
{
$form_password = $_POST['password'];
include("config.php");
if ($form_password == $password)
{
copy("$file","$upload_folder");
echo "<center><div class='norm'><b> was successfully uploaded To go to the file you have uploaded go to http://www.files.cloakshape.org/files</b></div></center>";
}
else
{
echo "<center><div class='norm'><b>The upload password was not correct, please go back and re-enter the password correctly.</b></div></center>";
}
}
else
{
?>
<div class="norm">This is a upload system, currently in progress of making </div>
<br>
<form action="<?php
$self_file = $_SERVER['PHP_SELF']; echo "$self_file"; ?>?upload=1" method="post" enctype="multipart/form-data" name="form1">
<table width="300" border="0" align="center">
<tr>
<td class="field">Password</td>
<td><input name="password" type="password"></td>
</tr>
<tr>
<td class="field">File to upload</td>
<td><input name="file" type="file" class="upload"></td>
</tr>
<tr>
<td width="336"><input type="submit" name="Submit" value="Upload" class="button"></td>
</tr>
</table>
<?php
}
?>
</form>
</div>
</body>
</html>
then the external file (config.php)
code: <?php
$password = '(my password)';
$upload_folder = '/files/';
?>
And it wont upload it too the files bit in my sever 
Thanks for any help
Nathan
|
|
06-20-2006 04:48 PM |
|
 |
Mnjul
forum super mod
     

plz wub me
Posts: 5396 Reputation: 58
– / / 
Joined: Nov 2002
Status: Away
|
RE: A little help with php please
I think you first need to do something so that $file will know what $_POST['file'] is...
Haven't coded PHP for a while, I could be wrong
By the way, I think it's not simply using copy function, you need something else to reach the uploaded file temporarily stored somewhere on the server., ah, I retract, perhaps you just forgot $file=$_POST['file']
Take a look at http://www.php.net/manual/en/features.file-upload...upload.post-method
This post was edited on 06-20-2006 at 04:55 PM by Mnjul.
|
|
06-20-2006 04:50 PM |
|
 |
Nathan
Veteran Member
    

Yeah, "large dimensions" ;)
Posts: 2978 Reputation: 76
– / / 
Joined: Apr 2005
|
O.P. RE: A little help with php please
huh...
could you just edit the code cos i am not sure what you mean 
Thansk
|
|
06-20-2006 05:08 PM |
|
 |
Mnjul
forum super mod
     

plz wub me
Posts: 5396 Reputation: 58
– / / 
Joined: Nov 2002
Status: Away
|
RE: A little help with php please
before this line:
code: copy("$file","$upload_folder");
add $file=$_POST['file'];
so that it becomes
code: $file=$_POST['file'];
copy("$file","$upload_folder");
Give it a try 
|
|
06-20-2006 05:15 PM |
|
 |
Nathan
Veteran Member
    

Yeah, "large dimensions" ;)
Posts: 2978 Reputation: 76
– / / 
Joined: Apr 2005
|
O.P. RE: A little help with php please
Thanks,
But nope it doesnt 
|
|
06-20-2006 05:19 PM |
|
 |
Plik
Veteran Member
    

Posts: 1487 Reputation: 46
35 / / –
Joined: Jun 2004
|
|
06-20-2006 05:34 PM |
|
 |
hmaster
Senior Member
   

Posts: 712 Reputation: 24
33 / / 
Joined: Nov 2004
|
RE: A little help with php please
This is some sample upload code I used, I think it's because you havn't used the $_FILES variables
code: #upload
if(@$_POST['submit']) {
$target_path = "gallery/images/";
$filename = basename($_FILES['uploadedfile']['name']);
$filename = str_replace(" ", "", $filename);
$target_file = $target_path . $filename;
if(empty($filename) || $filename == " ") {
header("Location: upload.php?error=1");
} elseif(file_exists($target_file) && @$_POST['ovrwrtf'] != "on") {
header("Location: upload.php?error=3");
} else {
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_file)) {
header("Location: img.php?filename=$filename");
} else {
header("Location: upload.php?error=4");
}
}
}
?>
I think move_uploaded_file() works better than copy() when uploading 
This post was edited on 06-20-2006 at 05:50 PM by hmaster.
|
|
06-20-2006 05:47 PM |
|
 |
-dt-
Scripting Contest Winner
    

;o
Posts: 1818 Reputation: 74
36 / / 
Joined: Mar 2004
|
RE: RE: A little help with php please
quote: Originally posted by hmaster
This is some sample upload code I used, I think it's because you havn't used the $_FILES variables
code: #upload
if(@$_POST['submit']) {
$target_path = "gallery/images/";
$filename = basename($_FILES['uploadedfile']['name']);
$filename = str_replace(" ", "", $filename);
$target_file = $target_path . $filename;
if(empty($filename) || $filename == " ") {
header("Location: upload.php?error=1");
} elseif(file_exists($target_file) && @$_POST['ovrwrtf'] != "on") {
header("Location: upload.php?error=3");
} else {
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_file)) {
header("Location: img.php?filename=$filename");
} else {
header("Location: upload.php?error=4");
}
}
}
?>
I think move_uploaded_file() works better than copy() when uploading 
Horrible use isset() instead of just ignoring the notice
This post was edited on 06-21-2006 at 03:49 AM by -dt-.
Happy Birthday, WDZ
|
|
06-21-2006 03:48 AM |
|
 |
Lou
Veteran Member
    

Posts: 2474 Reputation: 43
– / / 
Joined: Aug 2004
|
RE: A little help with php please
I made an uploader. Alright, there's no password protect, but you can just re-implement it in here.
The code is not 100% mine I admit it
EDIT: It seems I had removed the file extension blocker..You might want to add that back in if you ever remove that password.
Attachment: working uploader.zip (1.39 KB)
This file has been downloaded 179 time(s).
This post was edited on 06-21-2006 at 04:01 AM by Lou.
The future holds bright things in it\\\'s path, but only time will tell what they are and where they come from.
Messenger Stuff Forums
|
|
06-21-2006 03:58 AM |
|
 |
|