我想上傳一個圖像文件(例如 - 「C:\ Users \ Public \ Pictures \ 1.png」)到我的ftp服務器(ftp://srict.96.lt)。如何發送文件從本地計算機到我的服務器在PHP?
我有以下HTML代碼,它允許用戶從本地計算機中選擇文件。
<html>
<body>
<form action="imgup.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
現在在imgup.php我試着下面的代碼,但它說:「move_uploaded_file(/Hydrangeas.jpg):未能打開流:權限在/home/u704250527/public_html/imgup.php上否認第21" 行
<?php
$target_dir = "public_html/"; /* I also tried for "/" "root/public_html/" */
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if ($uploadOk == 0)
{
echo "Sorry, your file was not uploaded.";
}
else
{
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
{
echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";
}
else
{
echo "Sorry, there was an error uploading your file.";
}
}
?>
我需要的文件當用戶點擊上傳按鈕上傳。 我也嘗試在PHP中使用ftp,這也給我同樣的錯誤未能打開流。
<?php
// connect and login to FTP server
$ftp_server = "ftp.srict.96.lt";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$ftp_username="user";
$ftp_userpass="pass";
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$file = "D:\Picture1.png";
$fp = fopen($file,"r");
if (ftp_fput($ftp_conn, "1.png", $fp, FTP_ASCII))
{
echo "Successfully uploaded $file.";
}
else
{
echo "Error uploading $file.";
}
ftp_close($ftp_conn);
?>
你需要學習有關FTP –
我也用Google搜索一下,一切說move_uploaded_file()以將工作。但它不適合我。你能給我任何資源供我學習嗎?我真的很有興趣研究這一點,並在此工作。 – Sridharan
實際上,移動到您當前的服務器而不是ftp ..服務器將其移動到ftp服務器,您需要連接到ftp,然後發送它們..使用php讀取ftp –