Hi...
I want to move an uploaded file to another machine.I had given the file path to move_uploded_file() function including IP address .The folder is a shared folder.My code shown below.

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
   move_uploaded_file($_FILES["file"]["tmp_name"],"192.168.0.23/E:/pdf/" . $_FILES["file"]["name"]);


  echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

  }
?>

I am getting the error like as

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to access 240.jpg in C:\xampp\htdocs\divya\fileupload\upload_file.php on line 11

Dani AI

Generated

The PHP process must be able to write to the destination path you give it. Pointing at an IP plus a drive letter is not a valid filesystem path for the server; on Windows you either use a proper UNC share (\server\share...) and make sure Apache/PHP runs as a user that has network-share access, or you push the file over a network protocol (FTP/SFTP) from PHP. As hinted, a network-share approach is possible but often fails because the webserver account does not have credentials for the remote machine. The original upload should first land in PHP's temp folder, then be transferred onward.

If giving the webserver direct access to the share is acceptable, create a Windows share and grant the service account permission, or run Apache under a domain/local account with rights to that share. For many setups this is more work than it’s worth; an alternative is to transfer the file programmatically after upload. Example using PHP's FTP extension:

$local = $_FILES['file']['tmp_name'];
$remote = '/remote/path/' . basename($_FILES['file']['name']);
$conn = ftp_connect('192.168.0.23', 21, 10);
ftp_login($conn, 'username', 'password');
ftp_pasv($conn, true);
ftp_put($conn, $remote, $local, FTP_BINARY);
ftp_close($conn);

For encrypted transfers, use SFTP/SSH (ssh2) or curl with SFTP. These avoid giving the webserver direct SMB access and are better for security and logging. See PHP docs for ftp_put and the ssh2 SFTP functions for examples and required extensions.

Troubleshooting checklist: verify the share is writable by the account running PHP, test writing to the share with a simple PHP script run under the same service account, confirm firewall/SMB ports, escape backslashes in PHP string literals when using UNC paths, and avoid storing credentials in source control. PHP docs: move_uploaded_file, ftp_put, ssh2_sftp. For UNC path rules see Naming Files, Paths, and Namespaces.

You have to state your file move part with something such as "\\\ ... until you get to the final file destination. I think it is similar to trying to access another machine on your network through a browser such as \\ipaddress of the machine\
I hope this works.

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.