[英]Uploading an mp3 to my server from my iPhone app
It seems i have solved the first in a set of problems with my code.看来我已经解决了我的代码的一系列问题中的第一个问题。 The question I am talking about is this one: First Question .
我正在谈论的问题是:第一个问题。 As you can see the given answer is only about the objective-c code.
如您所见,给出的答案仅与 objective-c 代码有关。 This appears to be working correctly right now.
这似乎现在正常工作。
The problem seems to be the php code not finding the file as $HTTP_POST_FILES['mainfile']['name']
returns null.问题似乎是 php 代码找不到文件,因为
$HTTP_POST_FILES['mainfile']['name']
返回 null。 I'm not sure if the problem lies within the php code or the objective-c code.我不确定问题出在 php 代码还是 objective-c 代码中。 Both are below:
两者都在下面:
Objective-C code Objective-C 代码
NSString *theUrl = @"MyServerURL";//Sorry not showing this:)
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:theUrl]];
[request setFile:[soundFileURL path] forKey:@"mainfile"];
[request startSynchronous];
PHP code PHP代码
$SafeFile = $HTTP_POST_FILES['mainfile']['name'];
$uploaddir = "uploads/";
$path = $uploaddir.$SafeFile;
$mainfile = $HTTP_POST_FILES['mainfile'];
$toWrite .= "\nThe path to which the file should be saved = " . $path . "\n";
if($mainfile != null){ //AS LONG AS A FILE WAS SELECTED...
$toWrite .= "The file is NOT NONE!\n";
if(copy($HTTP_POST_FILES['mainfile']['tmp_name'], $path)){ //IF IT HAS BEEN COPIED...
$toWrite .= "The file was succesfully saved to the server! \n";
}
}
This $toWrite
variable gets written to a txt file.这个
$toWrite
变量被写入一个 txt 文件。 In this file i can see that at the first $toWrite
the $SafeFile
seems to be empty.在这个文件中,我可以看到在第一个
$toWrite
处$SafeFile
似乎是空的。 This led me to beleve that the file is not accessable or not sent at all..这使我相信该文件无法访问或根本没有发送..
If anyone can help me figure out this problem I would be most thankfull!如果有人能帮我解决这个问题,我将不胜感激!
['name']
can be empty. ['name']
可以为空。 It's not required that uploaded files cary a filename=
value.上传的文件不需要带有
filename=
值。 And regardless of that you should never use it unfiltered , as that opens the door to path traversal exploits.不管怎样,你永远不应该使用它unfiltered ,因为这为路径遍历漏洞打开了大门。
Your second problem might be the use of $HTTP_POST_FILES
, which was valid in PHP4.您的第二个问题可能是使用
$HTTP_POST_FILES
,这在 PHP4 中是有效的。 Nowadays that array is called $_FILES
.如今,该数组称为
$_FILES
。 To see if your upload succeeded at all and what descriptive fields are present, test with print_r($_FILES);
要查看您的上传是否成功以及存在哪些描述性字段,请使用
print_r($_FILES);
进行测试before you try anything else.在你尝试其他任何事情之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.