The client's file is uploaded to the server, the server returns the path to the file, and the client saves the file
Client:
<?php
Header (' Content-type:text/html;charset=utf8 ');
$url = ' http://192.168.1.118/legcc/aaa.php ';//The address of the server being accessed
$curl = Curl_init ();
$path = ' D:\www\ceshi\a02.jpeg ';//absolute path to the client file
$source = file_get_contents ($path);
$dir = Date (' y/m/d/', Time ());
$data = Array (' source ' = = $source, ' name ' = = ' A02 ', ' ext ' = = '. jpeg ', ' dir ' = = $dir);//Parameter
$re = curl_setopt ($curl, Curlopt_url, $url);
curl_setopt ($curl, Curlopt_returntransfer, true);
curl_setopt ($curl, Curlopt_post, true);
curl_setopt ($curl, Curlopt_postfields, $data);
$result = curl_exec ($curl);
Curl_close ($curl);
if (Json_decode ($result)->errrormessage ==1) {
Var_dump (Json_decode ($result));
} else if (Json_decode ($result)->errrormessage ==2) {
Echo ' file has been uploaded ~ ';
} else {
echo ' upload failed! ‘;
}
Service side:
<?php
The server receives the file that the client passes over to save
$basePath = ' e:\www\legcc/'; directory where files are stored
$path = $basePath. $_post[' dir '];
$results =[];
if (!is_dir ($path)) {
mkdir ($path, 0777,true);
}
if (!is_file ($path. $_post[' name '].$_post[' ext '))) {
$fuck = File_put_contents ($path. $_post[' name '].$_post[' ext '], $_post[' source ');
if ($fuck) {
$path 1 = ' http://192.168.1.118/legcc/'. $_post[' dir '. Rand (10,99). $_post[' ext '];
$results = [
errorcode=> $path 1,
Errrormessage=>1
];
}else{
$results = [
Errrormessage=>0
];
}
}else{
$results =[
Errrormessage=>2
];
}
echo Json_encode ($results);
The client's file is uploaded to the server, and the server returns the path to the file