简体   繁体   English

PHP文件上传在XAMPP中不起作用

[英]PHP file upload does not work in XAMPP

I'm trying to upload an xml file using an Android app I developed. 我正在尝试使用我开发的Android应用程序上传xml文件。

To do this, I used a free hosting space, and it works great. 为此,我使用了免费的托管空间,并且效果很好。 But now, I want to upload files to one of my pc's folders, using xampp as a web server. 但是现在,我想使用xampp作为Web服务器将文件上传到PC的一个文件夹中。

The problem is that when I try to upload files here something goes wrong. 问题是,当我尝试在此处上传文件时,出现了问题。 I am sure my php code is good, because it works with the hosting service I have my website on, so I only changed the path, as you can see below. 我确信我的php代码是好的,因为它可以与我在我的网站上提供的托管服务一起使用,所以我只更改了路径,如下所示。

For hosting service: 对于托管服务:

<?php
if (is_uploaded_file($_FILES['transactions']['tmp_name'])) {
    $uploads_dir = '/membri/cendav/gestione_magazzino/ExportData/';
    $tmp_name = $_FILES['transactions']['tmp_name'];
    $pic_name = $_FILES['transactions']['name'];
    move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
}
else{
    echo "File not uploaded successfully.";
}
?>

Now, the code for xampp, which is the same: 现在,xampp的代码是相同的:

<?php
if (is_uploaded_file($_FILES['transactions']['tmp_name'])) {
    $uploads_dir = 'exportdata/';
    $tmp_name = $_FILES['transactions']['tmp_name'];
    $pic_name = $_FILES['transactions']['name'];
    move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
}
else{
    echo "File not uploaded successfully.";
}
?>

As you can see, I only changed the $uploads_dir . 如您所见,我只更改了$uploads_dir The path from where I access the file upload.php , from my application http://10.0.0.202:1024/Warepad/ . 我从应用程序http://10.0.0.202:1024/Warepad/访问文件upload.php的路径。

I also changed the permissions of the exportdata/ folder, to everyone, but it still doesn't work. 我还更改了所有人的exportdata/文件夹的权限,但仍然无法使用。

PS I know there's a ton of these issues, but I still can't find what the problem is. 附言:我知道有很多这样的问题,但是我仍然找不到问题所在。

So, now it seems to work. 因此,现在看来可行。 It's strange, because the file upload.php is the same, and I haven't changed anything else! 很奇怪,因为文件upload.php是相同的,而我没有做任何其他更改!

?php
if (is_uploaded_file($_FILES['transactions']['tmp_name'])) {
    $uploads_dir = 'exportdata/';
    $tmp_name = $_FILES['transactions']['tmp_name'];
    $pic_name = $_FILES['transactions']['name'];
    move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
}
else{
    echo "File not uploaded successfully.";
}
?>

The Android app, now, is able to upload file correctly, but if I try to upload from an html form, it still doesn't work. 现在,Android应用程序能够正确上传文件,但是如果我尝试从html表单上传,它仍然无法正常工作。 Here's the html code: 这是html代码:

<html>

<head>
    <title>Upload</title>
    <meta charset="utf-8">
</head>

<body>
    <form action="upload.php" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="30000">
    Invia questo file: <input name="transactions" type="file">
    <input type="submit" value="Invia File">
    </form>
</body>

</html>

try this: 尝试这个:

<form action="fileupload.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" />
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM