Hi,
I am trying to write script to upload images to my webspace. So I decide to use ftp functions. I checked the php properties on my provider's web server and I see that FTP is enabled. This is the code I am using behind the form for selecting the image for uploading.
<html>
<head>
<title>Uploading ...</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><?php
$host = "myhostname";
$user = "myusername";
$pass = "mypassword";
// connecting to the remote FTP server;
$conn = ftp_connect("$host");
if (!$conn)
{
echo "Error: Could not connect to ftp server <br>";
exit;
}
echo "Connected to $host. <br>";
// logging in to the FTP server
@ $result = ftp_login($conn, $user, $pass);
if (!$result)
{
echo "Error: Could not log on as $user <br>";
ftp_quit($conn);
exit;
}
echo "logged in as $user <br>"; ?>
<h1>Uploading File</h1>
<?php
if ($userfile=="none")
{echo "Problem: no file uploaded";
exit;
}
$upfile=$DOCUMENT_ROOT."/mypath/".$userfile_name;
if (!copy($userfile, $upfile)){ echo "Problem: Could not move file into directory";
exit;
}
echo "File uploaded successfully <br><br>";
$fp = fopen($upfile, "r");
$contents = fread($fp, filesize($upfile));
fclose($fp);
?>
</body>
</html>
- When I try uploading image files I get this error message:
"Problem: Could not move file into directory"
- To cross-check the problem I try to upload a text file using the same script. This time I get:
Warning: copy(/home/mywebspace/teko.txt): failed to open stream: Permission denied in /home/mywebspace/upload.php on line 46
Problem: Could not move file into directory
Kindly help me understand what is happening. Is there a better way of writing scripts to handle the uploading of image files to my webspace?
Thank you for replying.