2015-09-14 25 views
-1

我在我的网络服务器上有一个名为photo.php的文件,这是躲避我。 我有一个用C++编写的程序,它将图片发送到photo.php。我如何将这些数据保存回图像?PHP和保存数据发送到一个文件

这是从提琴手4

POST http://osxchange.org/share/photo.php HTTP/1.1 
Host: osxchange.org 
Accept: */* 
Accept-Encoding: deflate, gzip 
Connection: Keep-Alive 
Content-Type: multipart/form-data; boundary=----------------------------0123abcdefab 
X-SecondLife-UDP-Listen-Port: 60424 
Content-Length: 55506 

------------------------------0123abcdefab 
Content-Disposition: form-data; name="caption" 


------------------------------0123abcdefab 
Content-Disposition: form-data; name="image"; filename="snapshot.jpg" 
Content-Type: image/jpg 
    JFIF   C    



$.' ",#(7),01444'9=82<.342 C   


2!!22222222222222222222222222222222222222222222222222 X "    

客户程序显示,它是将所述图像到所述主体的原始数据发送到photo.php如果让任何区别。

我也尝试保存所有作为GET POST PUT REQUEST发送,文件甚至显示它没有数据显示它正在发送提琴手。

这是由客户端处理照片上传代码

std::string imageFormat; 
    if (dynamic_cast<LLImagePNG*>(image.get())) 
    { 
     imageFormat = "png"; 
    } 
    else if (dynamic_cast<LLImageJPEG*>(image.get())) 
    { 
     imageFormat = "jpg"; 
    } 
    else 
    { 
     LL_WARNS() << "Image to upload is not a PNG or JPEG" << LL_ENDL; 
     return; 
    } 

    // All this code is mostly copied from LLWebProfile::post() 
    const std::string boundary = "----------------------------0123abcdefab"; 

    LLSD headers; 
    headers["Content-Type"] = "multipart/form-data; boundary=" + boundary; 

    std::ostringstream body; 

    // *NOTE: The order seems to matter. 
    body << "--" << boundary << "\r\n" 
      << "Content-Disposition: form-data; name=\"caption\"\r\n\r\n" 
      << caption << "\r\n"; 

    body << "--" << boundary << "\r\n" 
      << "Content-Disposition: form-data; name=\"image\"; filename=\"snapshot." << imageFormat << "\"\r\n" 
      << "Content-Type: image/" << imageFormat << "\r\n\r\n"; 

    // Insert the image data. 
    // *FIX: Treating this as a string will probably screw it up ... 
    U8* image_data = image->getData(); 
    for (S32 i = 0; i < image->getDataSize(); ++i) 
    { 
     body << image_data[i]; 
    } 

    body << "\r\n--" << boundary << "--\r\n"; 

    // postRaw() takes ownership of the buffer and releases it later. 
    size_t size = body.str().size(); 
    U8 *data = new U8[size]; 
    memcpy(data, body.str().data(), size); 

    // Note: we can use that route for different publish action. We should be able to use the same responder. 
    LLHTTPClient::postRaw("http://osxchange.org/share/photo.php", data, size, new LLFacebookShareResponder(), headers); 
} 
+0

没有看到任何代码的这将是非常困难任何人都可以帮助你。 –

+1

通过查看'$ _FILES ['image']'变量 – Scuzzy

+0

的内容开始,只需进行编辑以包含客户端代码。 –

回答

0

这样的事情将是一个良好的开端:

if (isset($_FILES['image'])) { 
    $savePath = './uploads/'; 
    $oldName = $_FILES['image']['tmp_name']; 
    $newName = $savePath.$_FILES['image']['name']; 

    move_uploaded_file($oldName, $newName); 
} 
相关问题