Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9261275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:06:31+00:00 2026-06-18T13:06:31+00:00

I am building a mobile site that runs from an API and have an

  • 0

I am building a mobile site that runs from an API and have an API CALL handler class which does all the calls which I run from a primary functions file.

The issue here is my files are not being sent through to the API and it’s not recognising what is a file and is returning a file not present error.

NOTE: ISSUE SOLVED AND WORKING CODE BELOW

Code Below:

FORM

<form id="uploadPhoto" action="<?php uploadStreamPhoto(); ?>" method="post" enctype="multipart/form-data">
    <input type="file" name="streamPhotoUpload" id="streamPhotoUpload" />
    <input type="submit" name="streamPhotoUploadSubmit" id="streamPhotoUploadSubmit" value="Upload" />
</form>

UPLOAD FUNCTION

function uploadStreamPhoto()
{

    if(isset($_POST['streamPhotoUploadSubmit']))
    {

        $apiHandler = new APIHandler();
        $result = $apiHandler->uploadStreamPhoto($_FILES['streamPhotoUpload']['tmp_name']);
        $json = json_decode($result);
        var_dump($json);

        //header('Location: '.BASE_URL.'stream-upload-preview');

    }

}

HANDLER METHOD

public function uploadStreamPhoto($file)
{

    $result = $this->request(API_URL_ADD_PHOTO, array(
    'accessToken' => $this->accessToken,
    'file' => "@$file;filename=".time().".jpg",
    'photoName' => time(),
    'albumName' => 'Stream'
    )); 

    return $result;

}

CURL REQUEST METHOD

/**
* Creates a curl request with the information passed in post fields
*
* @access private
* @param string $url
* @param array $postFields
* @return string
**/
private function request($url, $postFields = array())
{

    $curl = curl_init();

    //Check the SSL Matches the host
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);

    if($this->debug == true)
    {

        //Prevent curl from verifying the certificate
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

    }

    //Set the URL to call
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 0);

    //Set the results to be returned
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    //Set the curl request as a post
    curl_setopt($curl, CURLOPT_POST, 1); 

    //Set the post fields
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postFields); 

    $result = curl_exec($curl);

    if($result === false)
    {

        $result = 'Curl error: '.curl_error($curl);

    }

    curl_close($curl);

    return $result;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T13:06:32+00:00Added an answer on June 18, 2026 at 1:06 pm

    OK I have found out what the issue was, hopefully the solution will help a lot of people who don’t want to change how their code is in lieu of someone elses.

    cURL was not detecting that it was supposed to send this form as a multipart so it was sending the post as a default encoding meaning the other end wasn’t receiving the $_FILES variable.

    To solve this you need to give the postdata as an array, I was creating the string for the send, I have removed this and am giving the CURLOPT_POSTFIELDS an array.

    Another important thing when uploading directly from a form using cURL is to include the information for your file along with the actual file.

    My API Call handler now created the array as follows:

    public function uploadStreamPhoto($file)
    {
    
        $result = $this->request(API_URL_ADD_PHOTO, array(
        'accessToken' => $this->accessToken,
        'file' => "@$file;filename=".time().".jpg",
        'photoName' => time(),
        'albumName' => 'Stream'
        )); 
    
        return $result;
    
    }
    

    Take note that the $file variable is $_FILES[‘tmp_name’] You then also have to define the file name. I will be updating the question with the solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site that I'm building a mobile version for. I would like
I'm building my first jquery mobile site and have run into a problem. When
I'm currently building a mobile site and while testing using Windows7 which uses IE7,
I am building a mobile stylesheet for a site and have hit a snag
I've been building this site that will get run an API depending on the
I am building a site where I have several <video> elements (looped animations) that
Building a mobile site and wanted to create a rotator that would work just
I've recently finished building a mobile site and discovered a bug that only seems
I have a mobile site I am building. It has a Google static map
I am building a mobile site that works like a slideshow. There are a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.