Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    189
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Upload Script not working / naming problem

    Hi, I downloaded a script (upload_ac) to upload a single file.. basically the idea is that the user can replace a .pdf weekly with the new version and just upload it with this form, but it doesn't seem to be working. Here is the code.

    Code:
    <?php
    
    //in this example we keep file in folder upload 
    //$HTTP_POST_FILES['ufile']['name']; = upload file name
    //for example upload file name cartoon.gif . $path will be upload/cartoon.gif
    $path= "../folder/current-document.pdf".$HTTP_POST_FILES['ufile']['name'];
    if($ufile !=none)
    {
    if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
    {
    echo "<center><font face='arial,helvetica,sans-serif' size='2' color='#002e62'><b>UPLOAD SUCCESSFUL</b></font></center>"; 
    
    }
    else
    {
    echo "Error";
    }
    }
    ?>
    The uploader works when I use the above, but it names the file wrong:
    $path= "../folder/current-document.pdf".$HTTP_POST_FILES['ufile']['name'];

    file ends up in the folder and being called "current-document.pdfcurrent-document.pdf"

    when I make the path $path="../folder/".$HTTP_POST_FILES['ufile']['name'];
    then the upload doesn't even work? Am I missing something.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Try this to see if its any closer.

    PHP Code:
    $path"../folder/current-document$HTTP_POST_FILES['ufile']['name'].pdf"
    Or another option

    PHP Code:
    $path"../folder/current-document".$HTTP_POST_FILES['ufile']['name'].".pdf"
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Use $_FILES instead of HTTP_POST_FILES I believe that http_post_files was depricated as of PHP 5.

    Master of follies is almost right but you need to remove the .pdf from the end of the path because it is provided when you use the name value.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •