So I got these Codes.
<?php
$uploaddir = "upload/";
if(is_uploaded_file($_FILES['file']['tmp_name'])) {
$name = rand(1,1000000000000);
$uploadfile = $uploaddir . basename($name . ".png");
if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
echo $name . ".png";
}
else {
print_r($_FILES);
}
}
else {
echo "Upload Failed!!!";
print_r($_FILES);
}
?>
And this is my VB.NET code.
Dim Client As System.Net.WebClient = New System.Net.WebClient
Client.Headers.Add("Content-Type", "binary/octet-stream")
Dim result() As Byte = Client.UploadFile("/uploading/upload.php", "POST", filename)
Dim s As String = System.Text.Encoding.UTF8.GetString(result, 0, result.Length)
It is working all fine, the only thing is that the result I get back always adds this in front of every file . (It's only echo'ing like that, it does properly upload on my server) e.g /uploads/561708579306.png While it has to be /uploads/561708579306.png So the upload goes right, it gives the right name, which is /uploads/561708579306.png, but the echo seems to be giving this back /uploads/561708579306.png
Does anybody have a clue?
Sincerly, Jordy
Yes, This is a BOM problem.
There are two ways I have in mind.
save upload.php (and all other included phps) without BOM
The only way I know how is to save it with notepad++ and choose 'encode in UTF-8 Without BOM' from encoding tab.
Remove any other output before echo
Which seems to be better that the other solution. add ob_clean();
before every echo to clean data from upper lines.
Hope it helps.