Question:
i want to upload a txt file to http server using chilkat c++.but i m getting the error HTTP/1.1 404 Not Found blocking upload
c++ code
#include <CkUpload.h> #include <stdio.h> void ChilkatSample(void) { CkUpload upload; // Specify the page (ASP, ASP.NET, Perl, Python, Ruby, CGI, etc) // that will process the HTTP Upload. upload.put_Hostname("localhost/upload"); upload.put_Path("/uploader.php"); // Add one or more files to be uploaded. upload.AddFileReference("file1","d:\\hello.txt"); // Do the upload. The method returns when the upload // is completed. // This component also includes asynchronous upload capability, // which is demonstrated in another example. bool success; success = upload.BlockingUpload(); if (success != true) { printf("%s\n",upload.lastErrorText()); } else { printf("Files uploaded!\n"); } } int main() { ChilkatSample(); }
html
<form enctype="multipart/form-data" method="post" action="uploader.php"> Send this file: <input name="userfile" type="file" /><br /> <input type="submit" value="Send File" /> </form><form enctype="multipart/form-data" method="post" action="uploader.php"> Send this file: <input name="userfile" type="file" /><br /> <input type="submit" value="Send File" /> </form>
php
<?php if (move_uploaded_file($_FILES['userfile']['tmp_name'], "uploads{$_FILES['userfile']['name']}")) { print "Received {$_FILES['userfile']['name']} - its size is {$_FILES['userfile']['size']}"; } else { print "Upload failed!"; } ?>
@jpbro well after so many research now i am able to upload a file to asp.net server using above c++ chilkat program.when i m using php code to handle the uploaded file from the form.html the c++ program showing uploaded successfully but there is no file in the server .is there any problem in my php code? i m able to upload a file from browser to server using above php code but from the program its not ..
Unfortunately, I don't program with PHP, so I'm not very familiar with it and can't be of much help.
That said, when something appears successful (and the software on both ends of the connection are reporting success), but the file doesn't appear where you expect it to be, usually it has ended up somewhere unexpected (or under an unexpected filename in the expected location). Maybe if you output some more debugging info in your PHP code, it might indicate where it has actually gone? e.g.
<?php if (move_uploaded_file($_FILES['userfile']['tmp_name'], "uploads{$_FILES['userfile']['name']}")) { print "Received {$_FILES['userfile']['name']} - copied to {$_FILES['userfile']['name']} - its size is {$_FILES['userfile']['size']}"; print "Received {$_FILES['userfile']['name']} - or maybe copied to uploads{$_FILES['userfile']['name']} - its size is {$_FILES['userfile']['size']}"; } else { print "Upload failed!"; } ?>