0

Update: I have updated Chilkat. The latest version gives out more debug info, and its behaviour is different: It does not hang anymore at UploadInProgress. However, the problem still persists in the new version. I have therefore posted another question.

For completeness, here is the question anyways:

I have the following php file:

<?php
     move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
?> 

I am using it with Chilkat.Upload like this:

    Dim _Chil As New Chilkat.Upload
    _Chil.Ssl = True

    _Chil.Hostname = "www.mydomain.com"
    _Chil.Path = "/upload.php"
    _Chil.AddFileReference("file", PathToFileThatShouldBeUploaded)

    Dim bUploadStarted As Boolean = _Chil.BeginUpload()

    If Not bUploadStarted Then
        MessageBox.Show("Error starting the upload: " & NewLines(2) & _Chil.LastErrorText)
        Return
    End If

    Do While _Chil.UploadInProgress 'Never becomes False, so the loop does not exit / break
        _Chil.SleepMs(200)
    Loop

    Dim bSuccess As Boolean = _Chil.UploadSuccess
    If Not bSuccess Then
        MessageBox.Show("Error uploading: " & NewLines(2) & _Chil.LastErrorText)
    Else
        MessageBox.Show("Upload completed. :-)")
    End If

It used to work, but then my hoster updated php, and now it no longer works.

Chilkat does not reveal any error.

I believe I have to get the error from the server. However, I don't know how.

This is how I would start:

<?php
    if (move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]))
    {
        echo "Uploaded";
    }
    else
    {
        echo "File not uploaded. Err: ";
    }
?> 

2 questions:

How do I make it print out the error? I have read about

'.print_r($_FILES);
  1. How do I correctly include '.print_r($_FILES); in my php code?
  2. How could I receive / show this error while using Chilkat.Upload?

Thank you!

Edit:

This is my current code according to a comment:

https://example.com/upload.php?d:\test.avi

<?php
echo 'Error code: '.$_FILES['file']['error'];
move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
?>
tmighty
  • 10,734
  • 21
  • 104
  • 218
  • Before you try to move a file take a look at `$_FILES['file']['error']` which should indicate any problem that PHP is seeing. The error codes are explained [here](https://www.php.net/manual/en/features.file-upload.errors.php) – Tangentially Perpendicular Sep 02 '21 at 22:03
  • @TangentiallyPerpendicular Thank you. Can you tell me how I could inspect the error? Is there a way to call my php script from the browser instead of from a VB.NET script? If I could call it from the browser, I could use echo, I think. – tmighty Sep 02 '21 at 22:08
  • There's a wealth of information in the [PHP manual](https://www.php.net/manual/en/features.file-upload.post-method.php), including some sample code. If you want to use a browser to debug the upload script just browse to the address you're using as a target for your current .NET uploader. A simple `echo 'Error code: '.$_FILES['file']['error'];` at the top of `upload.php` should tell you what you need to know. – Tangentially Perpendicular Sep 02 '21 at 22:43
  • @TangentiallyPerpendicular I have added an edit to my post. Is that what you're suggesting? I'm asking because it just shows: Error code: when I type https://example.com/upload.php?d:\test.avi in my browser. – tmighty Sep 02 '21 at 22:51
  • 1
    No, that is of course absolutely pointless as a debug measure here; you can not perform a file upload, by simply appending a file name in the URL. If you have no way of viewing received debug output in your .NET script, then write it to some file on the server instead, so that you can check on it afterwards. – CBroe Sep 03 '21 at 06:37

1 Answers1

0

Your VB.NET code fragment using Chilkat.Upload seems to be missing the call to actually send the upload (BeginUpload) as shown here: https://www.example-code.com/vbnet/upload_asynchHttps.asp

Chilkat Software
  • 1,405
  • 1
  • 9
  • 8
  • You're right. During my tests, I actually deleted the line _chil.BeginUpload(). I have added it back up. Now however, this loop never exits / breaks: Do While _Chil.UploadInProgress. So I guess that is a sign that it doesn't work. How would I go on debugging now? – tmighty Sep 03 '21 at 13:19
  • Currently the error is that UploadInProgress never becomes false. – tmighty Sep 03 '21 at 14:04
  • I have updated to the last chilkat version. In this version, UploadInProgress does become false. I have posted another question for the new version. – tmighty Sep 03 '21 at 19:30