我正在尝试在 php 中上传文件但无法执行。我尝试上传的文件是一个 csv 文件,但这应该不是问题。我正在使用 php 上传我的文件。我也在尝试在同一页面中处理表单。以下是我的文件上传代码,但它不起作用...
<!DOCTYPE html>
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="file" name="csv_file">
<input type="submit" name="submit">
</form>
<?php
if(isset($_POST['submit'])) {
if(isset($_POST['csv_file'])) {
echo "<p>".$_POST['csv_file']." => file input successfull</p>";
fileUpload();
}
}
function fileUpload () {
$target_dir = "var/import/";
$file_name = $_FILES['csv_file']['name'];
$file_tmp = $_FILES['csv_file']['tmp_name'];
if (move_uploaded_file($file_tmp, $target_dir.$file_name)) {
echo "<h1>File Upload Success</h1>";
}
else {
echo "<h1>File Upload not successfull</h1>";
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我是magento2的新手,我发现很难在新版本中获得常规代码片段.所以,请帮助我在这里解释magento2中以下片段的等价物:
Mage::getModel('catalog/product')->getCollection();
Mage::getModel('sales/order');
Mage::getModel('catalog/category')->getCollection();
Mage::getModel('customer/customer');
Mage::getModel('cart/quote');
Mage::getModel('checkout/cart');
Mage::getSingleton('customer/session');
Mage::getModel('catalog/category')->load(id);
Run Code Online (Sandbox Code Playgroud)
我希望这个问题能帮助所有新的magento 2开发人员在一个地方找到相关的查询.
我正在使用反应头盔将元素推入头部。需要用到的代码片段是GTM和电商跟踪的。但是,无论如何,我无法找到在 head 中插入脚本的方法。文档显示了从外部源加载。该代码片段具有正在使用的动态值。
该文档来自此网址: react-helmet
<Helmet script={[
{src: "http://include.com/pathtojs.js", type: "text/javascript"},
{type: "application/ld+json", innerHTML: `{ "@context": "http://schema.org" }`}
]}
/>
Run Code Online (Sandbox Code Playgroud) 我无法在 app.js 中设置上下文状态,我以某种方式在其中获得空值,但可以在子组件中访问它。
\n我想在用户访问页面时在 app.js 中设置上下文状态,以便我可以在整个应用程序中使用它,例如根据用户是否登录显示不同的标题
\n根据请求的沙盒 URL -> https://codesandbox.io/s/quizzical-snyder-2qghj?file=/src/App.js
\n我正在关注https://upmostly.com/tutorials/how-to-use-the-usecontext-hook-in-react
\n应用程序.js
\n// import installed dependencies\nimport React, { useEffect, useContext } from \'react\';\nimport { BrowserRouter as Router, Switch, Route } from \'react-router-dom\';\n\n// import custom contexts\nimport { AuthContext, AuthContextProvider } from \'./contexts/auth/AuthContext\';\n\n// import pages\nimport Homepage from \'./pages/homepage/Homepage\';\n\n// import components\nimport Footer from \'./components/footer/Footer\';\nimport Header from \'./components/header/Header\';\n\nexport default function App() {\n const [authState, setAuthState] = useContext(AuthContext);\n\n useEffect(() => {\n console.log(authState); // prints *{}*\n console.log(setAuthState); // prints *() …
Run Code Online (Sandbox Code Playgroud)