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. 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. I’m not sure if the problem lies within the php code or the objective-c code. Both are below:
Objective-C code
NSString *theUrl = @"MyServerURL";//Sorry not showing this:)
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:theUrl]];
[request setFile:[soundFileURL path] forKey:@"mainfile"];
[request startSynchronous];
PHP code
$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. In this file i can see that at the first $toWrite the $SafeFile seems to be empty. 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. It’s not required that uploaded files cary afilename=value. And regardless of that you should never use it unfiltered, as that opens the door to path traversal exploits.Your second problem might be the use of
$HTTP_POST_FILES, which was valid in PHP4. Nowadays that array is called$_FILES. To see if your upload succeeded at all and what descriptive fields are present, test withprint_r($_FILES);before you try anything else.