Lately, I have been working on an upload form. The idea is that users can upload their files to a remote FTP server. However, it does not work as expected.
Before I even start uploading the file, I get the following error: "Cannot move uploaded file to working directory". Again, I have not yet started uploading a file.
Here is my PHP code:
<?php
//FTP variabelen met de values
$host = "radioprogrammabank.nl";
$user = "***";
$pass = "***";
//location I want to send the uploaded file to (it is remote)
$destDir = "/domains/radioprogrammabank.nl/public_html/wp/wp-content/uploads";
$dehost = $_POST[$host];
$deuser = $_POST[$user];
$depass = $_POST[$pass];
$dedestDir = $_POST[$destDir];
$workDir = "\Users\stagiaire01\Uploads"; // definieer het lokale systeem
// get temporary file name for the uploaded file
$tmpName = basename($_FILES['file']['tmp_name']);
// copy uploaded file into the current directory
move_uploaded_file($_FILES['file']['tmp_name'], $workDir."/".$tmpName) or die('Cannot move uploaded file to working directory');
// maak connectie, als het niet werkt. Die en geef een melding
$conn = ftp_connect($host) or die ("Cannot initiate connection to host");
// send access parameters
ftp_login($conn, $user, $pass) or die("Cannot login");
// Voer de file upload uit
$upload = ftp_put($conn, $destDir."/".$_FILES['file']['name'], $workDir."/".$tmpName, FTP_BINARY);
// check upload status
// display message
if (!$upload) {
echo "Upload mislukt";
} else {
echo "Upload geslaagd";
}
// sluit de FTP connectie
ftp_close($conn);
// verwijder de lokale kopie van het bestand
unlink($workDir."/".$tmpName) or die("Cannot delete uploaded file from working directory -- manual deletion recommended");
?>
My HTML code:
<html>
<body>
<h2>U kunt hier uw album uploaden</h2>
<form enctype="multipart/form-data" method="post" action="upload.php">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
File <br />
<input type="file" name="file" /><p />
<input type="submit" name="submit" value="Upload Album" />
</form>
</body>
[xyz-ips snippet="verbindftp"]
</html>
You may wonder why I have a shortcode in my HTML. The code is written in Wordpress. I use a plugin in which I can write PHP. The code works when writing this shortcode.
I have also tried doing a var_dump of $_FILES which tells me the following:
"array(0) { } Upload misluktCannot delete uploaded file from working directory -- manual deletion recommended"
I do not know why I get this message when doing a var_dump. I have set my host, username, password, and direction in my values above. The password and username are not shown because of security reasons.
I could not find any answers to this question on StackOverflow. However, I do hope I provided you with enough information to help me out. I expect to be able to upload a file to a remote FTP server.
Greetings,
Parsa_237