I'm sorry! Asking the great gods a question. Could not get the get value passed over

Source: Internet
Author: User
This post was last edited by eason_____________ on 2013-07-25 16:41:04

Database

The problem now is that if you don't upload the file, just upload the text. You can get the value of $_get. If you upload a file, you cannot get it. Please see below for specific code. is a JSON pass value.

Html

      <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                                                          



index.php

 
  Imagestart (); $gettitle =$_get[' title '; $getcontent =$_get[' content '];if ($_get[' imgshows ']== ' none ') {//If there are no files On the execution of this sentence $sql= "insert into Json_bbs values (', '". $gettitle. "', '". $getcontent. "', '", ". Date ()." ', ') "; mysql_query ($ SQL);} Else{if ($i->imagestauts = = 1) {//There is a file to execute this sentence//is here to get the value $sql= "insert into Json_bbs values (', '". $gettitle. "', '". $ GetContent. "', ' ', '". Time (). "', '"; mysql_query ($sql);}? >



Reply to discussion (solution)


uploadimage.php
/**
*
* Image Upload Class
* @author Chenyue
*
* @param $mageStauts picture upload status 1 is the normal state
* @param $iamgePath picture upload successfully saved in the path of the database
* @param $imagePathTemp temporarily save the path of the uploaded image to the database successfully
* @param upload file path $destination _folder
* @param $imageName uploaded image name (customizable)
* @param $fileArray An array of picture information uploaded
* @param $updateImage to determine if the original image is updated 0 means not updated, 1 means update
* @param $uptypes support for uploaded image types
* @param max_file_size support upload the maximum type of picture
* @param types of ImageType pictures
*
*/
Class uploadimage{

public $imageStauts = 1;
Public $iamgePath = ';
Private $imagePathTemp = "";
Private $destination _folder;
Private $imageName;
Private $fileArray;
Private $updateImage = 0;
Private $uptypes = Array (
' Image/jpg ',
' Image/jpeg ',
' Image/png ',
' Image/x-png ');

Private $imageType = array (' jpg ', ' jpeg ', ' png ');
Const max_file_size=2000000;


/**
* Constructor function
* @param $file An array of picture information uploaded
* @param $destination Upload file path
* @param $name uploaded image name (customizable) is not defined, the uploaded image is named Time ()
* @param $dbPath picture upload successfully saved in the path of the database
* @param $update to determine whether to update the original image 0 is not updated, 1 indicates an update. The update will replace the image that already exists.
*/
function __construct ($file, $destination = "", $name = "", $dbPath = "", $update =0) {

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 checking 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-type
if (!in_array (Strtolower ($file [' type ']), $this->uptypes) && $this->imagestauts = = = 1) {
$this->imagestauts = ' unsupported '. $file [' type ']. ' Types of files ';
}
*/
Prevents PHP code from being added to the comment field in the picture metadata
Pass binary matching Checks
$fileInfo = pathinfo ($this->filearray[' name ');
$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 work on photo upload
*/
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:time ();
$destination = $this->destination_folder. $n. $fileType;//Picture Local Path
$this->imagepathtemp = $this->imagepathtemp. $n. '. '. $fileType;//The path to be saved in the database

Upload image, if there is no image update existing pictures
if (file_exists ($destination) && $this->imagestauts = = = 1 && $this->updateimage = = 0) {
$this->imagestauts = ' picture already exists ';
}

Upload image, if there is an update image
if ($this->imagestauts = = = 1 && $this->updateimage = = 1) {
$deleteIMageDestination = $this->destination_folder. $n; Picture saves a local path, contains a file name but does not contain a picture suffix name
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 pictures
* @param $path picture in the local save path
* @return successfully returned 1 failed to return 0
*/
function DeleteImage ($path) {
if (!empty ($path)) {
foreach ($this->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 image to be deleted cannot be empty ';
return 0;
}
}

}

?>

Or is that a problem?
How to change the picture can not be uploaded?

Or is that a problem?
How to change the picture can not be uploaded?

Now the image can be uploaded, can also be written to the database. is if there are files and pictures uploaded together.
Can not get the value of $_get

Or is that a problem?
How to change the picture can not be uploaded?

Is there a problem with the class?
Now the process is:
If the value uploads the text, it is inserted directly into the database.
If you upload a text image, wait for the image to upload and then perform the Insert database operation.

if ($i->imagestauts = = 1) This is to determine whether the image upload completed

First verify that the code has gone to this if block, if it is not in this block, how do you know that the value of get not taken?
if ($i->imagestauts = = 1) {
echo "AAAAAA";
}

Also, your code is not quite the same as it was before.
$i->dowork ();
$i->imagecheck ();
That's the logic?

First verify that the code has gone to this if block, if it is not in this block, how do you know that the value of get not taken?
if ($i->imagestauts = = 1) {
echo "AAAAAA";
}

Also, your code is not quite the same as it was before.
$i->dowork ();
$i->imagecheck ();
That's the logic?

$i->imagestart ();
Replaced by:
$i->dowork ();
$i->imagecheck ();
if ($i->imagestauts = = 1)
can go
can be inserted into the database.
The image address can be inserted into the database, that is, get the value can not be inserted into the database,


A low-level error
if ($i imagestauts = = 1)
is status

public $imageStauts = 1;

That's how it's written in my class.

A low-level error
if ($i imagestauts = = 1)
is status
public $imageStauts = 1;

That's how it's written in my class.

A low-level error
if ($i imagestauts = = 1)
is status

Just can't find the reason, if upload picture always get the value of get not to upload picture on line .....


A low-level error
if ($i imagestauts = = 1)
is status
public $imageStauts = 1;

That's how it's written in my class.
... It's wrong to be mistaken.

A low-level error
if ($i imagestauts = = 1)
is status

If you do not add this judgment if ($i->imagestauts = = 1) You can get the Get value

Plus debug:
else{
echo "to Else";
if ($i->imagestauts = = 1) {
echo "to Status";
$sql = "INSERT into Json_bbs values (', '".) $gettitle. "', '". $getcontent. "', ' ', '". Time (). "', '";
mysql_query ($sql);
}
}

And see what the problem is.


A low-level error
if ($i imagestauts = = 1)
is status

If you do not add this judgment if ($i->imagestauts = = 1) You can get the Get value

That is not not the value, but imagestauts not equal to 1, there is no way to go to this block of code.



A low-level error
if ($i imagestauts = = 1)
is status

If you do not add this judgment if ($i->imagestauts = = 1) You can get the Get value

That is not not the value, but imagestauts not equal to 1, there is no way to go to this block of code.

But I put $sql = "INSERT into Json_bbs values (', '".) $gettitle. "', '". $getcontent. "', '", "". Time (). "', '"; You can insert the accents into the database by any character.

if ($i->imagestauts = = 1) This step is passed.

This is an arbitrarily typed character that cancels the Get value:



This is the get value.




A low-level error
if ($i imagestauts = = 1)
is status

If you do not add this judgment if ($i->imagestauts = = 1) You can get the Get value

That is not not the value, but imagestauts not equal to 1, there is no way to go to this block of code.

But I put $sql = "INSERT into Json_bbs values (', '".) $gettitle. "', '". $getcontent. "', '", "". Time (). "', '"; You can insert the accents into the database by any character.
First add the debug code, SQL also echo out to see the results.

First add the debug code, SQL also echo out to see the results.

The result is above.

So the picture is still ready to be uploaded, right?

Your text and pictures are uploaded separately, so your receiver program has been executed twice
Once is only get over the text data
Once was the only upload to come over the picture
What you need to do is to recognize that the two data is the same commit from the same browser (see the code image is selected at the time of submission, right?). )
Well, your uexuploadermgr.createuploader (1,uploadhttp); Misplaced it, it was right.

In order to identify which is coming from the same browser, you can use cookies preferably session convenient to record status
To recognize that it was from the same commit, you can append the sequence number to the URL
That's roughly what it looks like.

var uploadhttp = "http://localhost/json/bbs/index.php"; var num = 0;function upload () {  var url = uploadhttp + '? t= ' + N Um;   if ($$ ("Fb-title"). value!= ' && $$ ("Fb-content"). value!= "&& document.getElementById (" Showpic "). src== "") {    uexuploadermgr.createuploader (1,url);    var fbtitle = $$ ("Fb-title"). Value;    var fbcontent = $$ ("Fb-content"). Value;    URL + = ' &title= ' +fbtitle+ ' &content= ' +fbcontent+ "&imgshows=none";    $.getjson (url,function (data) {      });


Session_Start (); if (Isset ($_session[' t ") && $_session[' t '] = = $_get[' t ']) {  //same time commit  //modify database based on incoming data }else {  $_session[' t '] = $_get[' t '];  Inserts the database $_session[' last ', based on the data that was passed in,  = ID of the previous insertion, used as the credential for the modification}

So the picture is still ready to be uploaded, right?

Your text and pictures are uploaded separately, so your receiver program has been executed twice
Once is only get over the text data
Once was the only upload to come over the picture
What you need to do is to recognize that the two data is the same commit from the same browser (see the code image is selected at the time of submission, right?). )
Well, your uexuploadermgr.createuploader (1,uploadhttp); Misplaced it, it was right.

In order to identify which is coming from the same browser, you can use cookies preferably session convenient to record status
To recognize that it was from the same commit, you can append the sequence number to the URL
That's roughly what it looks like.

var uploadhttp = "http://localhost/json/bbs/index.php"; var num = 0;function upload () {  var url = uploadhttp + '? t= ' + N Um;   if ($$ ("Fb-title"). value!= ' && $$ ("Fb-content"). value!= "&& document.getElementById (" Showpic "). src== "") {    uexuploadermgr.createuploader (1,url);    var fbtitle = $$ ("Fb-title"). Value;    var fbcontent = $$ ("Fb-content"). Value;    URL + = ' &title= ' +fbtitle+ ' &content= ' +fbcontent+ "&imgshows=none";    $.getjson (url,function (data) {      });


Session_Start (); if (Isset ($_session[' t ") && $_session[' t '] = = $_get[' t ']) {  //same time commit  //modify database based on incoming data }else {  $_session[' t '] = $_get[' t '];  Inserts the database $_session[' last ', based on the data that was passed in,  = ID of the previous insertion, used as the credential for the modification}


This is not the case, pictures and text are uploaded together
if ($$ ("Fb-title"). value!= ' && $$ ("Fb-content"). value!= "&& document.getElementById (" Showpic "). src== "")//This is to judge there is no picture this is no picture directly inserted into the database
if ($$ ("Fb-title"). value!= ' && $$ ("Fb-content"). value!= "&& document.getElementById (" Showpic "). Src!= "")//This is a picture has a picture to perform the operation of uploading pictures.

After performing the operation of the picture,
if ($i->imagestauts = = 1) Determine if the picture is finished uploading.

If the upload is complete, insert the text and the picture into the database, not separate execution.

Now is the IF ($i->imagestauts = = 1) {The value of get can not be obtained on this side.} If the $_get[' title ' is replaced by any character, it will be OK}

How to say you can understand is two times upload it?
This is the upload text, get way, cannot upload the file. Uploading a file requires at least the Post method
$.getjson (url,function (data) {

This is to create an upload component, no form can only be uploaded with components
Uexuploadermgr.createuploader (1,uploadhttp);

Add
Because it's a two-time commit, there's a two-record issue in your other post.

It should be said that the code now is far from the code of your other posts reasonable

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.