This post was last edited by eason_____________ on 2013-07-25 11:25:44
MySQL Database
Do a phone upload image to the server function. But get to execute INSERT statement to execute two times!
index.php
DoWork (); $i->imagecheck (); $sql = "INSERT into Json_bbs values (', '". $gettitle. "', '". $getcontent. "', '". $i Iamgepath. "', '". Time (). "', '"; mysql_query ($sql);? >
uploadimage.php
imagestauts = ' error! Wrong HTTP method! ';} if (Is_array ($file) && count ($file) >0 &&!empty ($destination)) {$this->filearray = $file; $this- >destination_folder = $destination; $this->imagename = $name; $this->imagepathtemp = $dbPath; $this UpdateImage = $update;} else{$this->imagestauts = ' initialization failed ';}} /** * Start image upload */function Imagestart () {if ($this->imagestauts = = = 1) {$this->imagecheck ();} if ($this->imagestauts = = = 1) {$this->dowork ();}} /*** * Picture Check work */function Imagecheck () {$file = $this->filearray;//print_r ($file); if (!is_uploaded_file ($file [' Tmp_ Name ']) && $this->imagestauts = = = 1) {$this->imagestauts = ' picture does not exist! '; }if (Uploadimage::max_file_size < $file [' size '] && $this->imagestauts = = = 1) {$this->imagestauts = ' File is too large ';} /*//Check Mime-typeif (!in_array (Strtolower ($file [' type ']), $this->uptypes) && $this->imagestauts = = = 1) {$ this->imagestauts = ' unsupported '. $file [' type ']. ' Types of files ';} *///prevents the inclusion of PHP code in the comment field of the picture metadata//Check $fileinfo = pathinfo ($this->filearray[' name ') via binary matching; $fileType = Strtolower ($fileInfo [' extension ']); if (!in_array ($fileType, $this->imagetype) && $this->imagestauts = = = 1) {$ This->imagestauts = ' not supported '. $fileType. ' file of type ';} if (!file_exists ($this->destination_folder) && $this->imagestauts = = = 1) {mkdir ($this->destination_ folder,0777)///Set file Permissions}}/** * * Start image upload work */function doWork () {$fileName = $this->filearray[' tmp_name ']; $fileSize = GetImageSize ($fileName); $fileInfo = PathInfo ($this->filearray[' name '); $fileType = Strtolower ($fileInfo [' Extension ']); $n =!empty ($this->imagename)? $this->imagename:date ("y_n_d_h_i_s"); $destination = $this->destination_folder. $n. $fileType;//Picture Local Path $this->imagepathtemp = $this->imagepathtemp. $n. $fileType;//The path to be saved in the database//upload picture, if the picture exists does not update the existing picture if (File_exists ($destination) && $this->imagestauts = = 1 & & $this->updateimage = = 0) {$this->imagestauts = ' picture already exists ';} Upload a picture, if the picture exists update already have the picture if ($this->imagestauts = = = 1 && $this->updateimage = = 1) {$deleteIMageDestination = $ This->destination_folder. $n; The picture holds the local path, contains the file name, but does not contain the picture suffix if ($this->deleteimage ($deleteIMageDestination)) {}else{$this->imagestauts = ' Delete existing picture failed ';}} if (!move_uploaded_file ($fileName, $destination) && $this->imagestauts = = = 1) {$this->imagestauts = ' Transmission error ';} if ($this->imagestauts = = = 1) {$this->iamgepath = $this->imagepathtemp;return $this->imagestauts;}} /** * Delete picture * @param $path picture in local save path * @return successfully returned 1 failed to return 0*/function DeleteImage ($path) {if (!empty ($path)) {foreach ($this-& Gt;imagetype as $type) {$_path = $path. '. '. $type, if (file_exists ($_path)) {//echo $_path;if (!unlink ($_path)) {$this->imagestauts = ' Delete existing picture failed '; return 0;}} return 1;} else{$this->imagestauts = ' The path of the picture to be deleted cannot be empty '; return 0;}}? >
Reply to discussion (solution)
Ask for help look!
This is the only index.php code?
Was it executed and then refreshed? Jump out?
This is the only index.php code?
Was it executed and then refreshed? Jump out?
And there is the title and content JS passed over
This is the only index.php code?
Was it executed and then refreshed? Jump out?
If you judge index.php
if ($_get[' title ']!= ') {$sql = "insert into Json_bbs values (', '". $gettitle. "', '". $getcontent. "', '". $i->iamgepath . "', '". Time (). "', ')"; mysql_query ($sql);}
When executed, only one piece of data is inserted, but the $i->iamgepath value is not obtained, and the $i->iamgepath is empty.
If you do not judge, insert the following two data:
ID title content Images time UID
127 AAA yyyyy 1374722311 0
2013_7_25_11_18_32.jpg 1374722312 0
This is the only index.php code?
Was it executed and then refreshed? Jump out?
And there is the title and content JS passed over
JS came from the title and content? How is it delivered?
Will JS pass when the script executes, submit the upload image and then executed the insert. So it's two records?
This is the only index.php code?
Was it executed and then refreshed? Jump out?
If you judge index.php
if ($_get[' title ']!= ') {$sql = "insert into Json_bbs values (', '". $gettitle. "', '". $getcontent. "', '". $i->iamgepath . "', '". Time (). "', ')"; mysql_query ($sql);}
When executed, only one piece of data is inserted, but the $i->iamgepath value is not obtained, and the $i->iamgepath is empty.
If you do not judge, insert the following two data:
ID title content Images time UID
127 AAA yyyyy 1374722311 0
2013_7_25_11_18_32.jpg 1374722312 0
That's what you see. 2 different operations perform the resulting insert
Your 2 actions, one should be the update action, it should be said that the subsequent execution of the action can only be updated action, not the insertion action
So you have a logic problem, inserting 2 data is normal.
Look at your form.
Look at your form.
This is the only index.php code?
Was it executed and then refreshed? Jump out?
And there is the title and content JS passed over
JS came from the title and content? How is it delivered?
Will JS pass when the script executes, submit the upload image and then executed the insert. So it's two records?
JSON passes the
Look at your form.
The owner says the form, you give the database.
Is the code of the form part and the JS part.
Look at your form.
The owner says the form, you give the database.
Is the code of the form part and the JS part.
Ajax?
Pass it over and execute the insert?
The submission form is executed once again.
No, just two data?
Look at your form.
<title> </title>
<textarea placeholder="请输入内容" name="content" rows="7" id="fb-content"></textarea>
x
Add a picture
Release
Choose from a mobile album Take Pictures Cancel
Look at your form.
The owner says the form, you give the database.
Is the code of the form part and the JS part.
Ajax?
Pass it over and execute the insert?
The submission form is executed once again.
No, just two data?
If I judge
is if ($_get["title"]!= ") {
}
had been executed once.
But the inserted data $i->iamgepath value is empty what's going on here?
Your text submission and the file upload itself are separate
Your text submission and the file upload itself are separate
Well, this is the mobile app I made with Appcan.
Your text submission and the file upload itself are separate
The question of inserting two now solves the problem of not getting the $i->iamgepath value when inserting.
But when insert is two, $i->iamgepath.
This is when the text is submitted
The var url = ' http://localhost/json/bbs/index.php?title= ' +fbtitle+ ' &content= ' +fbcontent;
106 $.getjson (Url,function (data) {
This is the file that is being submitted
Uexuploadermgr.uploadfile (1,upload_image_url, "filename", 4);
Although file submissions are initiated before the text is submitted
102 Uexuploadermgr.createuploader (1,UPLOADHTTP);
But general file upload is always slower than text submission, so you can get the get data first, then receive the upload file
But what if the opposite is true?
Your text submission and the file upload itself are separate
The question of inserting two now solves the problem of not getting the $i->iamgepath value when inserting.
But when insert is two, $i->iamgepath.
Give you a thought and suggestions, in fact, many sites are also in use, that is:
Picture part with the IFRAME, in the AJAX submission is the time to perform the picture part, and then get back to the normal image address (here is not inserted in the database, purely upload pictures) after the execution of the text form part later, the image address is used with a parameter, so that you can insert the database with the text, There's only one piece of data.
Your text submission and the file upload itself are separate
The question of inserting two now solves the problem of not getting the $i->iamgepath value when inserting.
But when insert is two, $i->iamgepath.
Give you a thought and suggestions, in fact, many sites are also in use, that is:
Picture part with the IFRAME, in the AJAX submission is the time to perform the picture part, and then get back to the normal image address (here is not inserted in the database, purely upload pictures) after the execution of the text form part later, the image address is used with a parameter, so that you can insert the database with the text, There's only one piece of data.
Thank you to the two moderator to the idea. I was trying.