File Upload Service in PHP

0 votes

Hi,

I use File Upload Server - Upload File in PHP

What is the content of $filePath ?

filePath - The local path for the file.

I tried "C:\\Users\\username\\Desktop\\che.jpg", "C:/Users/username/Desktop/che.jpg", "file:///C:/Users/username/Desktop/che.jpg" and web url

I got the same result

Error Message :File Not Found
Error AppErrorCode :
Error HttpErrorCode :

this is my code

 

class uploadtest
{
public function uploadtest() {
        $this->sp = new ServiceAPI("XXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXX");
    }
 
/******* upload file *******/
    public function UploadFile() {
       try
       {
            $uploadService = $this->sp->buildUploadService();
            $fileName = "UploadTest01";     
$fileType = "Upload.IMAGE";     
$filePath = "C:/Users/username/Desktop/che.jpg";
$description = "File Description Flow";  
$upload = $uploadService->uploadFile($fileName, $filePath, $fileType, $description);   
print_r("fileName is " . $upload->getFileList()->getName()."<br/>");  
print_r("fileType is " . $upload->getFileList()->getType()."<br/>");  
$jsonResponse = $upload->toString();   
print_r($jsonResponse);
        }
        catch(App42Exception $ex)
        {
            print_r("Error Message :".$ex->getMessage()."<br/>");
            print_r("Error AppErrorCode :".$ex->getAppErrorCode()."<br/>");
            print_r("Error HttpErrorCode :".$ex->getHttpErrorCode()."<br/>");
        }
 
    }
 
}
 
 
$mytest = new uploadtest;
$mytest -> UploadFile();
 
What is the content of $filePath ?
Please help me !
Thank you !
asked Apr 8, 2014 in App42 Cloud API-BaaS by guo (110 points)
recategorized Apr 8, 2014 by guo

1 Answer

0 votes
 
Best answer

Hi guo , 

1- Your fileType is wrong use UploadFileType::IMAGE

2-  First you check  that file is exist or not. Its working fine our side with the path format given by you "C:/Users/Shephertz/Pictures/che.jpg" or  "C:\\Users\\Shephertz\\Pictures\\che.jpg" 

answered Apr 8, 2014 by samita.mahajan (60 points)
selected Apr 16, 2014 by guo
Hi guo,
1- We remove unwanted warning from our sdk in new release 2.1 . Please download (https://github.com/shephertz/App42_PHP_SDK/archive/master.zip  ) latest sdk
2. We remove namespace please donot use " use com\shephertz\app42\paas\sdk\php\upload\UploadFileType; "
and use "include_once 'PHP/2.0/UploadFileType.php'; "
Please Find code of  uploadFile in given link  http://codeshare.io/64oyr  .
Hi,
Thanks for your reply !

I use version 2.1 and I don't use " use com\shephertz\app42\paas\sdk\php\upload\UploadFileType; "
and use "include_once 'PHP/2.0/UploadFileType.php'; "

This can solve aforementioned problems, but now I have
But now I remain a error, 'File Not Found'
The complete error message is
" Fatal error: Uncaught exception 'App42Exception' with message 'File Not Found' in /home/ideabusd/public_html/guotest/app42/PHP/2.1/UploadService.php:668 Stack trace: #0 /home/ideabusd/public_html/guotest/app42/index.php(47): UploadService->uploadFile('UploadTest01', 'C:/che.jpg', 'IMAGE', 'File Descriptio...') #1 {main} thrown in /home/ideabusd/public_html/guotest/app42/PHP/2.1/UploadService.php on line 668 "

I tried "C:/che.jpg" and "C:\\che.jpg", but it can't find this file.
I am sure this file in my computer C:\

I have tried code http://codeshare.io/64oyr, I got same error message.

How cand I do for filepath ?
We are using file_exists method to validate file path. for more info please read this .
http://www.php.net/manual/en/function.file-exists.php
Because this page says ---
This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir.
File Upload Client Authorize
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...