内容类型
个人空间
版块
Articles
Store
相册
Calendar
下载
博客
墨香年少 发布的所有帖子
-
void Uploador::on_submit_photo_clicked() { QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart _uid; _uid.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"uid\"")); _uid.setBody(uid.toUtf8()); multiPart->append(_uid); QHttpPart _key; _key.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"key\"")); _key.setBody("ABCD"); multiPart->append(_key); QHttpPart tit; tit.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"title\"")); tit.setBody(ui->lineEdit_title->text().toUtf8()); multiPart->append(tit); QHttpPart tags; tags.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"tags\"")); tags.setBody(ui->lineEdit_tag->text().toUtf8()); multiPart->append(tags); QHttpPart _filename; _filename.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"filename\"")); _filename.setBody(filename.toUtf8()); multiPart->append(_filename); QString ext = get_ext(filename); QHttpPart imagePart; imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(ext)); imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"stream\"")); file = new QFile(); if(local.length() > 2) { file = new QFile(local); local_file = local; } else { local_file = tmp_folder+filename; file = new QFile(local_file); } file->open(QIODevice::ReadOnly); imagePart.setBodyDevice(file); file->setParent(multiPart); multiPart->append(imagePart); QUrl url("http://www.abc.com/client/api"); QNetworkRequest request(url); QNetworkAccessManager *mgr = new QNetworkAccessManager(); QNetworkReply *reply = mgr->post(request, multiPart); multiPart->setParent(reply); connect(mgr,SIGNAL(finished(QNetworkReply*)),this,SLOT(slot_requestFinished(QNetworkReply*))); }
-
Windows Registry Editor Version 5.00 ; Change Extension's File Type [HKEY_CURRENT_USER\Software\Classes\.jpg] @="PhotoViewer.FileAssoc.Tiff" ; Change Extension's File Type [HKEY_CURRENT_USER\Software\Classes\.jpeg] @="PhotoViewer.FileAssoc.Tiff" ; Change Extension's File Type [HKEY_CURRENT_USER\Software\Classes\.gif] @="PhotoViewer.FileAssoc.Tiff" ; Change Extension's File Type [HKEY_CURRENT_USER\Software\Classes\.png] @="PhotoViewer.FileAssoc.Tiff" ; Change Extension's File Type [HKEY_CURRENT_USER\Software\Classes\.bmp] @="PhotoViewer.FileAssoc.Tiff" ; Change Extension's File Type [HKEY_CURRENT_USER\Software\Classes\.tiff] @="PhotoViewer.FileAssoc.Tiff" ; Change Extension's File Type [HKEY_CURRENT_USER\Software\Classes\.ico] @="PhotoViewer.FileAssoc.Tiff" 保存为win10_get_photoviewer.reg 然后双击即可。
- 1篇 回复
-
- 1
-
#!/bin/sh port=`netstat -lnt|grep 3306|wc -l` time=$(date "+%Y-%m-%d %H:%M:%S") if [ $port -ne 1 ];then echo "mysql die time:"$time >> /web/mysql_die.log /usr/bin/phpstudy start else echo "1" >> /web/mysql_ok.log fi 上面的脚本命名为:checkmysql.sh 然后: crontab:*/1 * * * * /usr/bin/sh /web/checkmysql.sh
-
#include <time.h> #include <stdio.h> #include <unistd.h> #include <dirent.h> #include <string.h> //备份目录 char back_dir[50] = "/存储路径/"; //检测目录是不是存在 int is_dir_exist(const char*dir_path){ if(dir_path==NULL){ return -1; } if(opendir(dir_path)==NULL){ return -1; } return 0; } //备份数据库 int back_db(char* db_name) { char cmd_db1[200]={0}; char db1[15] = {0}; strcat(db1,db_name); char file1[100] = {0}; sprintf(file1,"%s/%s.sql.gz",back_dir,db1); sprintf(cmd_db1,"/phpstudy/mysql/bin/mysqldump -u root -p密码 %s | gzip > %s",db1,file1); system(cmd_db1); return 0; } int main( void ) { time_t t = time(0); char t_date[15]; strftime( t_date, sizeof(t_date), "%Y_%m_%d",localtime(&t) ); strcat(back_dir,t_date);//将备份目录拼接日期 int dir_exists = is_dir_exist(back_dir); if(dir_exists < 0) { printf("dir[%s] is not exists.\n",back_dir); //back dir not exists, create char cmd1[50] = {0}; sprintf(cmd1,"mkdir %s",back_dir); system(cmd1); printf("dir[%s] created success.\n",back_dir); } //开始执行备份命令 back_db("数据库1"); back_db("数据库2"); back_db("数据库3"); return 0; }
-
public string upload_file(string web_api, string imgPath, Dictionary<string, string> ps) { string title = imgPath.Substring(imgPath.LastIndexOf("/") + 1); if (!File.Exists(imgPath)) { return "file_not_exists."; } FileStream fs = new FileStream(imgPath, FileMode.Open, FileAccess.Read); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); // Generate post objects Dictionary<string, object> postParameters = new Dictionary<string, object>(); postParameters.Add("fileformat", "jpg"); postParameters.Add("stream", new FormUpload.FileParameter(data, title, "image/jpeg")); foreach (KeyValuePair<string, string> kv in ps) { postParameters.Add(kv.Key, kv.Value); } postParameters.Add("usebinary", "1"); // Create request and receive response string userAgent = "Someone"; HttpWebResponse webResponse = FormUpload.MultipartFormDataPost(web_api, userAgent, postParameters); // Process response StreamReader responseReader = new StreamReader(webResponse.GetResponseStream()); string fullResponse = responseReader.ReadToEnd(); webResponse.Close(); return fullResponse; } public static class FormUpload { private static readonly Encoding encoding = Encoding.UTF8; public static HttpWebResponse MultipartFormDataPost(string postUrl, string userAgent, Dictionary<string, object> postParameters) { string formDataBoundary = String.Format("----------{0:N}", Guid.NewGuid()); string contentType = "multipart/form-data; boundary=" + formDataBoundary; byte[] formData = GetMultipartFormData(postParameters, formDataBoundary); return PostForm(postUrl, userAgent, contentType, formData); } private static HttpWebResponse PostForm(string postUrl, string userAgent, string contentType, byte[] formData) { HttpWebRequest request = WebRequest.Create(postUrl) as HttpWebRequest; if (request == null) { throw new NullReferenceException("request is not a http request"); } // Set up the request properties. request.Method = "POST"; request.ContentType = contentType; request.UserAgent = userAgent; request.CookieContainer = new CookieContainer(); request.ContentLength = formData.Length; // You could add authentication here as well if needed: // request.PreAuthenticate = true; // request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested; // request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes("username" + ":" + "password"))); // Send the form data to the request. using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(formData, 0, formData.Length); requestStream.Close(); } return request.GetResponse() as HttpWebResponse; } private static byte[] GetMultipartFormData(Dictionary<string, object> postParameters, string boundary) { Stream formDataStream = new System.IO.MemoryStream(); bool needsCLRF = false; foreach (var param in postParameters) { // Thanks to feedback from commenters, add a CRLF to allow multiple parameters to be added. // Skip it on the first parameter, add it to subsequent parameters. if (needsCLRF) formDataStream.Write(encoding.GetBytes("\r\n"), 0, encoding.GetByteCount("\r\n")); needsCLRF = true; if (param.Value is FileParameter) { FileParameter fileToUpload = (FileParameter)param.Value; // Add just the first part of this param, since we will write the file data directly to the Stream string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n", boundary, param.Key, fileToUpload.FileName ?? param.Key, fileToUpload.ContentType ?? "application/octet-stream"); formDataStream.Write(encoding.GetBytes(header), 0, encoding.GetByteCount(header)); // Write the file data directly to the Stream, rather than serializing it to a string. formDataStream.Write(fileToUpload.File, 0, fileToUpload.File.Length); } else { string postData = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"\r\n\r\n{2}", boundary, param.Key, param.Value); formDataStream.Write(encoding.GetBytes(postData), 0, encoding.GetByteCount(postData)); } } // Add the end of the request. Start with a newline string footer = "\r\n--" + boundary + "--\r\n"; formDataStream.Write(encoding.GetBytes(footer), 0, encoding.GetByteCount(footer)); // Dump the Stream into a byte[] formDataStream.Position = 0; byte[] formData = new byte[formDataStream.Length]; formDataStream.Read(formData, 0, formData.Length); formDataStream.Close(); return formData; } public class FileParameter { public byte[] File { get; set; } public string FileName { get; set; } public string ContentType { get; set; } public FileParameter(byte[] file) : this(file, null) { } public FileParameter(byte[] file, string filename) : this(file, filename, null) { } public FileParameter(byte[] file, string filename, string contenttype) { File = file; FileName = filename; ContentType = contenttype; } } }
-
public int upload_file(string web_api, string file_path, string file_name, string title, string tags) { if (file_name == "") { return 1; } string imgPath = file_path + file_name; // Read file data FileStream fs = new FileStream(imgPath, FileMode.Open, FileAccess.Read); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); // Generate post objects Dictionary<string, object> postParameters = new Dictionary<string, object>(); postParameters.Add("fileformat", "jpg"); postParameters.Add("stream", new FormUpload.FileParameter(data, title, "image/jpeg")); postParameters.Add("uid", "2"); postParameters.Add("album_id", "0"); postParameters.Add("filename", file_name); postParameters.Add("title", tags); postParameters.Add("tags", tags); postParameters.Add("usebinary", "1"); // Create request and receive response string userAgent = "Someone"; HttpWebResponse webResponse = FormUpload.MultipartFormDataPost(web_api, userAgent, postParameters); // Process response StreamReader responseReader = new StreamReader(webResponse.GetResponseStream()); string fullResponse = responseReader.ReadToEnd(); webResponse.Close(); if (fullResponse == "OK") { return 0; } return 1; } public static class FormUpload { private static readonly Encoding encoding = Encoding.UTF8; public static HttpWebResponse MultipartFormDataPost(string postUrl, string userAgent, Dictionary<string, object> postParameters) { string formDataBoundary = String.Format("----------{0:N}", Guid.NewGuid()); string contentType = "multipart/form-data; boundary=" + formDataBoundary; byte[] formData = GetMultipartFormData(postParameters, formDataBoundary); return PostForm(postUrl, userAgent, contentType, formData); } private static HttpWebResponse PostForm(string postUrl, string userAgent, string contentType, byte[] formData) { HttpWebRequest request = WebRequest.Create(postUrl) as HttpWebRequest; if (request == null) { throw new NullReferenceException("request is not a http request"); } // Set up the request properties. request.Method = "POST"; request.ContentType = contentType; request.UserAgent = userAgent; request.CookieContainer = new CookieContainer(); request.ContentLength = formData.Length; // You could add authentication here as well if needed: // request.PreAuthenticate = true; // request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested; // request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes("username" + ":" + "password"))); // Send the form data to the request. using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(formData, 0, formData.Length); requestStream.Close(); } return request.GetResponse() as HttpWebResponse; } private static byte[] GetMultipartFormData(Dictionary<string, object> postParameters, string boundary) { Stream formDataStream = new System.IO.MemoryStream(); bool needsCLRF = false; foreach (var param in postParameters) { // Thanks to feedback from commenters, add a CRLF to allow multiple parameters to be added. // Skip it on the first parameter, add it to subsequent parameters. if (needsCLRF) formDataStream.Write(encoding.GetBytes("\r\n"), 0, encoding.GetByteCount("\r\n")); needsCLRF = true; if (param.Value is FileParameter) { FileParameter fileToUpload = (FileParameter)param.Value; // Add just the first part of this param, since we will write the file data directly to the Stream string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n", boundary, param.Key, fileToUpload.FileName ?? param.Key, fileToUpload.ContentType ?? "application/octet-stream"); formDataStream.Write(encoding.GetBytes(header), 0, encoding.GetByteCount(header)); // Write the file data directly to the Stream, rather than serializing it to a string. formDataStream.Write(fileToUpload.File, 0, fileToUpload.File.Length); } else { string postData = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"\r\n\r\n{2}", boundary, param.Key, param.Value); formDataStream.Write(encoding.GetBytes(postData), 0, encoding.GetByteCount(postData)); } } // Add the end of the request. Start with a newline string footer = "\r\n--" + boundary + "--\r\n"; formDataStream.Write(encoding.GetBytes(footer), 0, encoding.GetByteCount(footer)); // Dump the Stream into a byte[] formDataStream.Position = 0; byte[] formData = new byte[formDataStream.Length]; formDataStream.Read(formData, 0, formData.Length); formDataStream.Close(); return formData; } public class FileParameter { public byte[] File { get; set; } public string FileName { get; set; } public string ContentType { get; set; } public FileParameter(byte[] file) : this(file, null) { } public FileParameter(byte[] file, string filename) : this(file, filename, null) { } public FileParameter(byte[] file, string filename, string contenttype) { File = file; FileName = filename; ContentType = contenttype; } } }
-
private string getHTML(string url) { if (url.Substring(0, 4) != "http") { return "error"; } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode.ToString() != "OK") { return "error"; } if (response.StatusCode == HttpStatusCode.NotFound) return "error"; if (response.StatusCode == HttpStatusCode.InternalServerError) return "error"; if (response.StatusCode == HttpStatusCode.BadGateway) return "error"; Stream ResponseStream = response.GetResponseStream(); StreamReader sr = new StreamReader(ResponseStream, Encoding.UTF8); string html = sr.ReadToEnd(); sr.Close(); ResponseStream.Close(); return html; } catch (Exception e) { return "error"; } return "error"; }
-
public static bool SavePhotoFromUrl(string FileName, string Url) { bool Value = false; WebResponse response = null; Stream stream = null; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); response = request.GetResponse(); stream = response.GetResponseStream(); if (!response.ContentType.ToLower().StartsWith("text/")) { Value = SaveBinaryFile(response, FileName); } } catch (Exception err) { string errMsg = err.ToString(); } return Value; } private static bool SaveBinaryFile(WebResponse response, string FileName) { bool Value = true; byte[] buffer = new byte[1024]; try { if (File.Exists(FileName)) File.Delete(FileName); Stream outStream = System.IO.File.Create(FileName); Stream inStream = response.GetResponseStream(); int l; do { l = inStream.Read(buffer, 0, buffer.Length); if (l > 0) outStream.Write(buffer, 0, l); } while (l > 0); outStream.Close(); inStream.Close(); } catch { Value = false; } return Value; }