我编写了php来上传文件并扫描目录以将它们显示为链接,扫描目录运行良好我可以看到我在目录中创建的文本文件,但我无法将本地文件移动到所需的目录。没有文件执行后出现。
我认为问题可能包含在这一行:
move_uploaded_file($_FILES["file"]["tmp_name"],"/var/www/BlueTapeLogin/upload".$_FILES["file"]["name"]);
我真正想要的是将图像上传到 /var/www/BlueTapeLogin/upload 中的目录,而我的 php 文件位于 /var/www/BlueTapeLogin/upload_image.php 我怎样才能更改代码以使其正常工作?提前致谢。
请看我的完整代码:
<html>
<head>
<?php
try
{
if (!empty($_POST["delete"])){
$delete=$_POST["delete"];
echo"we have the command delete this file:";
echo $delete;
$file = "upload/".$delete;
echo "/n***************";
echo "you want delete :";
echo $file;
echo "***************";
if (!unlink($file))
{
echo ("Error deleting $file");
}
else
{
echo ("Deleted $file");
}
}else{}
}catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
?>
<?php
move_uploaded_file($_FILES["file"]["tmp_name"],"/var/www/BlueTapeLogin/upload".$_FILES["file"]["name"]);
?>
<?php
$dir=scandir("/var/www/BlueTapeLogin/upload") ;
for($j=0;$j<count($dir);$j++){
echo $dir[$j];
echo"\n";
$target = $dir[$j]; // This is the file that already exists
$link = $dir[$j]; // This the filename that you want to link it to
echo "<a href=upload/".$link.">".$link."</a>";
}
?>
</head>
<body>
<form action="upload_image.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit"><br>
<label for="file">Delete</label>
<input type="text" name="delete" id="delete"><br>
<input type="submit" name="submit" value="Submit">
</form>
<a href="http://localhost/front2.php">logout</a>
</body>
</html>