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,

I changed my filetype => $fileType = "UploadFileType::IMAGE";
and I am sure file che.jpg in my desktop, my operation system is Windows 7, file path is "C:/Users/ideabus/Desktop/che.jpg" or "C:\\Users\\ideabus\\Desktop\\che.jpg", I got the same Error Message.

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

This is my code
https://drive.google.com/file/d/0B-xy7zqF9K0-RlZfQlV5b0hvOVU/edit?usp=sharing

Could show your code to me ?



Thank you !
Hi ,
1-  fileType is not string and use this code snippet

  public function testUploadFile() {
        $uploadService = $this->sp->buildUploadService();
        $fileName = "fileName" . time();
        $uploadObj = $uploadService->uploadFile($fileName, "C:\\Users\\Shephertz\\Desktop\\che.jpg", UploadFileType::IMAGE, "Description");
        print_r($uploadObj->toString());
        $success = $uploadObj->isResponseSuccess();
        $fileList = $uploadObj->getFileList();
        foreach($fileList as $files )
            {

          print_r("FileName is : ".$files->getName().PHP_EOL);
          print_r("Type is : ".$files->getType() .PHP_EOL);
          print_r("Url is : ".$files->getUrl() .PHP_EOL);
          print_r("TinyUrl is: ".$files->getTinyUrl() .PHP_EOL);
          print_r("Description is: ".$files->getDescription().PHP_EOL);
         }
    
    }
Hi,
thanks for your reply !

I use this
$upload = $uploadService->uploadFile($fileName, $filePath, UploadFileType::IMAGE, $description);

but I got other error code below

Fatal error: Class 'UploadFileType' not found

How can I do ?

Thank you !
Hi,
1- you should have to import this.

use com\shephertz\app42\paas\sdk\php\upload\UploadFileType;
include_once 'PHP/1.2/UploadFileType.php';  

2- We Re-factor  SDK in new version 2.0(https://github.com/shephertz/App42_PHP_SDK/tree/master/) .Please Use new source code in your file.
Hi,
I follow this tutorial to do
http://api.shephertz.com/app42-docs/file-upload-service/#upload_file

and I use version 2.0, but I got error message bellow


0
Warning: Missing argument 3 for UploadService::__construct(), called in /home/ideabusd/public_html/guotest/app42/PHP/2.0/App42API.php on line 238 and defined in /home/ideabusd/public_html/guotest/app42/PHP/2.0/UploadService.php on line 34

Notice: Undefined variable: baseURL in /home/ideabusd/public_html/guotest/app42/PHP/2.0/UploadService.php on line 38

Fatal error: Class 'com\shephertz\app42\paas\sdk\php\upload\UploadFileType' not found in /home/ideabusd/public_html/guotest/app42/index.php on line 45


This is my code
https://drive.google.com/file/d/0B-xy7zqF9K0-eEdhcGIxSFdYdTQ/edit?usp=sharing

Could give me some help ?
Thank you !
Hi,
Could give me a complete code ?

Thank you !
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
...