I have a script that uploads files to a folder and it works lovely when im testing on my XAMPP box, if someone else tries to upload it says

Warning: copy(C:/xampp/htdocs/data/mottramg/AEGON.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\training\upload.php on line 27
Could not copy file.

now this tells me, it can see where to copy the file too, but cant find the temp file? script is below:

<?php
$directory = $_GET['dir'];
$phpbbdir = "/data/" . $directory . "/";
// Set the maximum uploadable file size => 512000 = 500kb 
    $maxfilesize = 512000; 
// Is the file larger than it is allowed to be? 
    if($_FILES['userfile']['size'] > $maxfilesize) { 
        die("File too large"); 
    }
// Where will the file be uploaded to? 
    $uploaddir = $_SERVER['DOCUMENT_ROOT'] . $phpbbdir; 
// What is the files temporary name? 
    $file = $_FILES['userfile']['tmp_name']; 
// What is the files actual name? 
    $filename = $_FILES['userfile']['name']; 
// Does this file already exist on the server? 
    if(file_exists($uploaddir . $filename)) 
    { 
//die("A file with that name already exists on this server."); 
    echo $filename . " already exists";
    die ();
    }
    else { 
// This file does not already exist, so copy it. 
        copy($file, $uploaddir.$filename) or die("Could not copy file."); 
    } 
    // All done! :-) 
    echo $filename . " Uploaded to " .$uploaddir . " sucessfully</font>";
?> 
</body>

can someone suggest why it works for me on the box, but not someone else accessing the web pages? they can see everything else fine..

line 25 will be the error not line 27 as the error suggests, I took out 2 lines when I pasted here ;)

The most common reason why you get this error is because the file or directory doesn't exist. Here is a list of other reason why you may get this error:

Wrong permission - Make sure to set permissions correctly

Directory doesn't exist - Make sure that the directory "data" exists un. Also make sure that it is spelled correctly and has the correct lower case and upcase as your script.

File doesn't exist, spelled wrong, lower/upper case or permission is not set correctly

Please re-check your code if it meets the above!!

yep, it all meets the above, if I upload a file it works. if my friend on a different PC trys it, he gets the error. (we are on the same network and he can see all the web pages fine)

What if you use your friend's details on the PC that works for you?
What if your friend uses your details on his machine?
What if your friend changes his $_GET['dir'] variable to 'mottram' in the URL?
Did you create the upload directory manually or let the script create it?
What if you delete your upload directory (/mottram/) and upload the image again, does it work okay?

After running some tests, it only works from my machine, which does imply it cant find a path or it is indeed permissions, yet i have given full access on the data folder within the web app...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.