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 7779255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:36:15+00:00 2026-06-01T18:36:15+00:00

I made a REST Service which is heavily based on this tutorial . I

  • 0

I made a REST Service which is heavily based on this tutorial. I also made a REST Request library which is heavily based on this tutorial. (Basically, a bunch of switch on $_SERVER['REQUEST_METHOD']). the api also make requests with cURL.

protected function executePost ($ch)
{
    if (!is_string($this->requestBody))  
    {  
        $this->buildPostBody();  
    }  

    curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);  
    curl_setopt($ch, CURLOPT_POST, 1);  

    $this->doExecute($ch); 
}

protected function doExecute (&$curlHandle)
{
    $this->setCurlOpts($curlHandle);  
    $this->responseBody = curl_exec($curlHandle);  
    $this->responseInfo = curl_getinfo($curlHandle);  

    curl_close($curlHandle);  
}

I have 2 simple HTML forms, one with a get method and one for the post method. When i use one of them with simple input text, works fine. I get/return the values in the service with no problem.

But I need to send an image from a HTML form, receive it in my service and then save it on the server.

Here is the part where I lunch make the query to the service.

print_r($_FILES);
//move_uploaded_file( $_FILES["image1"]["tmp_name"], "Images/" . $_FILES["image1"]["name"] ); when uncommented, This line actually works and save the image in my folder.

include("RestUtils.php");

$request = new RestRequestOperator('http://localhost:8080/REST/RestControler.php/user/1', 'POST', $_FILES);  
$request->execute();  

In my service, I receive the image infos , which are the tmp_name and the name. When I try to save the image with move_uploaded_file( and the right parameters , it doesn’t work.

I realise there is some sort of magic going there with the image file saved for a ‘short laps of time’ in the tmp folder. when i call my service, the image is already removed ?

Wrap up : I wonder if it is possible to send an image to a PHP REST API and they save it on their server.

EDIT : I added in the service.

if(file_exists($_POST["image1"]["tmp_name"] )){
     echo "file EXISTS<br>";
}else echo "NOPE.<br>";

if(is_uploaded_file($_POST["image1"]["tmp_name"] )){
     echo "is_uploaded_file TRUE<br>";
}else echo "is_uploaded_file FALSE<br> .";

if(move_uploaded_file( $_POST["image1"]["tmp_name"], "Images/" .$_POST["image1"]["name"] )){
     echo "move_uploaded_file SUCCESS ";
}else echo "NOT move_uploaded_file";

outputs : file EXISTS , is_uploaded_file FALSE, NOT move_uploaded_file
which means the file actually still exist in the service but is uploaded file returns falses, probably beacause I use the POST array in the service instead of the $_FILES array, which is empty in my service…….

  • 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-01T18:36:17+00:00Added an answer on June 1, 2026 at 6:36 pm

    Found it, works on local wamp PHP 5.3.4 !

    public static function processRequest()
    {
        case 'post':
           if(move_uploaded_file($_FILES["uploaded_file"]["tmp_name"] , "Images/" . $_FILES["uploaded_file"]["name"] )){
                        echo "move_uploaded_file SUCCESS ";
        ......................................                
    }
    ......................................           
    protected function executePost ($ch)
    {
        $tmpfile = $_FILES['image1']['tmp_name'];
        $filename = basename($_FILES['image1']['name']);
    
        $data = array(
            'uploaded_file' => '@' . $tmpfile . ';filename='.$filename,
        );
        curl_setopt($ch, CURLOPT_POST, 1);             
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
        //no need httpheaders
        $this->doExecute($ch); 
    }
    

    Thanks. Dave

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

Sidebar

Related Questions

I'm doing a POST request to a rest service made with django and piston
I'm trying to create a REST service which shows/adds/deletes/edits soccer data in a database.
Some background I am planning to writing a REST service which helps facilitate collaboration
I have made a REST Web service, that works with Visual Studios WCF Test
I have made a Rest Web Service: package org.jboss.samples.rs.webservices; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import
I was messing around with JAX-RS and made an application which calls REST services
I am writing an application that is consuming an in-house WCF-based REST service and
What are the prerequisites (or steps) to host a WCF REST based service on
I want to create a rest service, which should retrieve all the available HTTP
I am creating a web service which uses REST web services. The client side

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.