SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Strange error when using copy function

    Hello,

    I am now up to chapter 10 on "Build your own website using PHP & Mysql" and have hit a brick wall, could anybody assist.

    I have a simple file upload script which takes the input field type "file" and uses the $_FILES array to take the tmp name and copies it to my desired directory, but I get the following error.

    failed to open stream: HTTP wrapper does not support writeable connections in C:\wamp\www\db-sites\ch10\fileUpload.php on line 9
    The script is extremely basic:
    PHP Code:
    <?php
    $fileTempName 
    $_FILES['upload']['tmp_name'];
    $fileOrigName $_FILES['upload']['name'];
    $fileSize $_FILES['upload']['size'];
    $fileType $_FILES['upload']['type'];

    $targetFileName "http://localhost/db-sites/ch10/" $fileOrigName;

    if (!
    copy($fileTempName$targetFileName))
    {
        echo 
    "failed to copy file.";
    }
    ?>
    <html>
        <head>
            <title>file has been uploaded</title>
        </head>
        <body>
            <h1>file has been uploaded</h1>
            <ul>
                <li><?php echo $fileTempName?></li>
                <li><?php echo $fileOrigName?></li>
                <li><?php echo $fileSize?></li>
                <li><?php echo $fileType?></li>
                <li><?php echo $targetFileName?></li>
            </ul>
        </body>
    </html>
    Which makes me think it is a config / directory thing with Wamp?

    If it is any help, no matter what file I upload I can never get windows to find the $fileTempName.

    Perhaps someone has had experience with WAMP before?

    Many thanks

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    You should copy to a directory (like "c:\\wamp\\websites\\db-sites\\ch10") and not a URL.

    Also, for uploaded files it's better to use move_uploaded_file instead of copy
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

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