Page 1 of 1

Attachments

Posted: Thu Mar 11, 2010 5:49 am
by Jay87
I have the following code for adding attachments:

Code: Select all

[color=#FF0000]<?php[/color]
$uploaddir = date("F")." '".date("y");
[color=#0000FF]if[/color] ($_FILES["file"]["size"] < [color=#FF8000]2000000[/color])
  [color=#800080]{[/color]
  [color=#0000FF]if[/color] ($_FILES["file"]["error"] > [color=#FF8000]0[/color])
    [color=#800080]{[/color]
    [color=#0000FF]echo[/color] "Return Code: " . $_FILES["file"]["error"] . "<br />";
    [color=#800080]}[/color]
  [color=#0000FF]else[/color]
    [color=#800080]{[/color]
    [color=#0000FF]echo[/color] "Upload: " . $_FILES["file"]["name"] . "<br />";
    [color=#0000FF]echo[/color] "Type: " . $_FILES["file"]["type"] . "<br />";
    [color=#0000FF]echo[/color] "Size: " . ($_FILES["file"]["size"] / [color=#FF8000]1024[/color]) . " Kb<br />";
    [color=#0000FF]echo[/color] "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
 
    [color=#0000FF]if[/color] (file_exists("upload/" . $uploaddir."/". $_FILES["file"]["name"]))
      [color=#800080]{[/color]
      [color=#0000FF]echo[/color] $_FILES["file"]["name"] . " already exists. ";
      [color=#800080]}[/color]
    [color=#0000FF]else[/color]
      [color=#800080]{[/color] mkdir("uploads/" . $uploaddir);
      move_uploaded_file($_FILES["file"]["tmp_name"], "\\192.168.1.202\web\helpdesk-dev\upload/" . $uploaddir."/". $_FILES["file"]["name"]);
      [color=#0000FF]echo[/color] "Stored in: " . "upload/" . $uploaddir."/". $_FILES["file"]["name"];
      [color=#800080]}[/color]
    [color=#800080]}[/color]
  [color=#800080]}[/color]
else
  [color=#800080]{[/color]
  echo "Invalid file";
  [color=#800080]}[/color]
[color=#FF0000]?>[/color]
and

Code: Select all

        <table width=800 height=50% class='smooth'>
 
        <tr><td class=smooth height=10%>Attachement(s)</td></tr>
        <tr><td><?echo $_FILES["file"]["name"] ?></td></tr>
        </table>
        
        
        <form action="upload_file.php" method="post"
            enctype="multipart/form-data">
            <label for="file">Filename:</label>
            <input type="file" name="file" id="file" /> 
            <br />
            <input type="submit" name="submit" value="Submit" />
            </form>
When trying to attach the file, it all goes through fine and no errors pop up but the file i try and attach never shows up anywhere...

Any ideas?


:banghead:

Re: Attachments

Posted: Thu Mar 11, 2010 7:05 am
by rmrbest
Please, file is moved to target? and the problem was <tr><td><?echo $_FILES["file"]["name"] ?></td></tr> not appear name file??

Thanks,

Raul.

Re: Attachments

Posted: Thu Mar 11, 2010 8:31 am
by Jay87
the problem is that the file doesn't seem to upload anywhere, can't even find the temp file before it is supposed to move to the upload folder?!

Re: Attachments

Posted: Thu Mar 11, 2010 9:30 am
by rmrbest
First, the operating system is Windows? Note that you must put double \. On the other hand, you have permissions to the folder or directory you create?