在php(image)

时间:2015-12-22 09:06:38

标签: php html mysql

首先,我想为这个问题道歉,因为我知道已经有很多人要求这件事了。但我搜索的所有答案都没有解决我的问题。所以希望你考虑这个问题并帮助我解决这个问题。

所以基本上我正在尝试上传图像文件,当我提交时,会弹出错误:

Warning: move_uploaded_file(./images/jarvs.jpg): failed to open stream:

Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\phpA25F.tmp' to './images/jarvs.jpg'

我真的没有得到错误,但我知道当我试图从图像的路径传输图像并将其发送到我的目标文件夹(目标路径)时发生错误

所以继承我的代码:

HTML: <input id="profimagefile" name="profileimage" class="input-file" type="file">

PHP:

$targetPath = "images/";
$targetPath = $targetPath.basename($_FILES['profileimage']['name']);

 //name of the file
 $img = $_FILES['profileimage']['name'];
 $size = $_FILES['profileimage']['size'];
 $type = $_FILES['profileimage']['type'];

 if(move_uploaded_file($_FILES['profileimage']['tmp_name'], $targetPath))
 {
 $queryupload = "INSERT INTO images_profile (image_name, image_path, date_uploaded, emailAddress)
  VALUES ('$img', '$targetPath','$registerDate', '$email')";

 mysqli_query($conn, $queryupload);
 echo "The file ". basename($_FILES['profileimage']['name']). " has been uploaded." . "<br/>";
 }
 else {
 echo "Sorry, there was a problem uploading your file." . "<br/>";
 }

不介意插入数据库,它只是在图像移动到我的目标路径后的过程的一部分。 谢谢你回答

2 个答案:

答案 0 :(得分:0)

试试这个::

<强> HTML

void processMessage(String msg) {
    Log.i(TAG, "Changing Switch Status to ON: "+swLED.getText());
    swLED.setChecked(true);
    Log.i(TAG, "DONE");
}

  //THIS METHOD IS MQTT CLIENT CALL BACK METHOD On Message Recceive  
@Override
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
    String Message =  new String(mqttMessage.getPayload());
    Log.i(TAG, "messageArrived Topic:" + topic + " Message: " + Message);
    processMessage(Message);
}

public class MainActivity extends AppCompatActivity {
    Switch swLED = null;
    CompoundButton.OnCheckedChangeListener switchListener = new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    Log.i(TAG, "SWITCH ONNNNNN");
                } else {
                    Log.i(TAG, "SWITCH OFFFFFF");
                }
            }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        swLED = (Switch) findViewById(R.id.swLED);
        swLED.setOnCheckedChangeListener(switchListener);
    }
}

<强> PHP

<form enctype="multipart/form-data>
<input id="profimagefile" name="profileimage" class="input-file" type="file">
</form>

答案 1 :(得分:0)

试试这个..

$targetPath = "images/";
//create folder if not exist
if(!is_dir($targetPath)){
    if(!mkdir($targetPath, 0777, true)){
        die('Failed to create folder.');
    }   
}
//set folder's permissions writale and executable
chmod($targetPath, 0777);
$targetPath = $targetPath.basename($_FILES['profileimage']['name']);

 //name of the file
 $img = $_FILES['profileimage']['name'];
 $size = $_FILES['profileimage']['size'];
 $type = $_FILES['profileimage']['type'];

 if(move_uploaded_file($_FILES['profileimage']['tmp_name'], $targetPath))
 {
 $queryupload = "INSERT INTO images_profile (image_name, image_path, date_uploaded, emailAddress)
  VALUES ('$img', '$targetPath','$registerDate', '$email')";

 mysqli_query($conn, $queryupload);
 echo "The file ". basename($_FILES['profileimage']['name']). " has been uploaded." . "<br/>";
 }
 else {
 echo "Sorry, there was a problem uploading your file." . "<br/>";
 }