Shoutbox

A little help with php please - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: A little help with php please (/showthread.php?tid=60759)

A little help with php please by Nathan on 06-20-2006 at 04:48 PM

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 :S
Thanks for any help
Nathan
RE: A little help with php please by Mnjul on 06-20-2006 at 04:50 PM

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


RE: A little help with php please by Nathan on 06-20-2006 at 05:08 PM

huh...
could you just edit the code cos i am not sure what you mean :p
Thansk


RE: A little help with php please by Mnjul on 06-20-2006 at 05:15 PM

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 :)
RE: A little help with php please by Nathan on 06-20-2006 at 05:19 PM

Thanks,
But nope it doesnt :(


RE: A little help with php please by Plik on 06-20-2006 at 05:34 PM

Read through this: http://www.php.net/manual/en/features.file-upload.php

(i know i already said this on msn, but it will save anyone else the effort


RE: A little help with php please by hmaster on 06-20-2006 at 05:47 PM

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 *-)
RE: RE: A little help with php please by -dt- on 06-21-2006 at 03:48 AM

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
RE: A little help with php please by Lou on 06-21-2006 at 03:58 AM

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:P

EDIT: It seems I had removed the file extension blocker..You might want to add that back in if you ever remove that password.