首页 \ 问答 \ 文件路径插入多行MySQL和Php(File path insert multiple rows MySQL and Php)

文件路径插入多行MySQL和Php(File path insert multiple rows MySQL and Php)

我目前能够执行多个图像的上传,然后将文件路径插入数据库中的一行。 理想情况下,我需要找到一种方法来将这些文件路径作为具有自己ID的单独条目上载。 原因是我插入的图像路径被绑定到插入到单独表中的任务。

function upload_file_new_task(){

global $db;

if(isset($_POST['create'])) {
    $path = "../uploads/";
    for ($i=0; $i<count($_FILES['files']['name']); $i++) {
        $ext = explode('.', basename( $_FILES['files']['name'][$i]));
        $path = $path . md5(uniqid()) . "." . $ext[count($ext)-1]; 
        move_uploaded_file($_FILES['files']['tmp_name'][$i], $path);
    }

    $sql = "INSERT INTO upload_data (`image`) VALUES ('$path');";
    $res = mysqli_query($db,$sql);
    echo "<p>Post Created $date</p>";
}

}

因此将图像上载到/ uploads文件夹中,然后将该路径作为单行加载到数据库中, ID字段中具有id,并且路径被加载到image字段中。


I am currently able to perform an upload of multiple images and then inserting the file paths into a row in the database. Ideally I need to find a way to upload these files paths as separate entries with their own ID. The reason why is because the image paths I am inserting are to be bound to a task which is inserted into a separate table.

function upload_file_new_task(){

global $db;

if(isset($_POST['create'])) {
    $path = "../uploads/";
    for ($i=0; $i<count($_FILES['files']['name']); $i++) {
        $ext = explode('.', basename( $_FILES['files']['name'][$i]));
        $path = $path . md5(uniqid()) . "." . $ext[count($ext)-1]; 
        move_uploaded_file($_FILES['files']['tmp_name'][$i], $path);
    }

    $sql = "INSERT INTO upload_data (`image`) VALUES ('$path');";
    $res = mysqli_query($db,$sql);
    echo "<p>Post Created $date</p>";
}

}

So theimage is uploaded into the /uploads folder, the path is then loaded into the database as a single row with an id in the ID field and the path(s) are loaded into the image field.


原文:https://stackoverflow.com/questions/36514507
更新时间:2023-04-08 08:04

最满意答案

你可能想尝试简单的if slider_value1 != '' 。 这是一个比if not slider_value1更好的选项,因为后者将阻止0 ,你也可能不想这样做。


You might want to try the simple if slider_value1 != '' . This is a better option than if not slider_value1 because the latter will block out 0 also which you might not want to do.

相关问答

更多
  • 你可能想尝试简单的if slider_value1 != '' 。 这是一个比if not slider_value1更好的选项,因为后者将阻止0 ,你也可能不想这样做。 You might want to try the simple if slider_value1 != '' . This is a better option than if not slider_value1 because the latter will block out 0 also which you might not w ...
  • 首先将n减小到2或更低( while n > 2: .. n -= 1 ),然后测试n > 5 。 后一个测试永远不会通过,因为n现在总是2或更低。 第一次减少计算斐波纳契序列,该序列中的第6个值为8(在1,1,2,3和5之后)。 为避免出现问题,请使用简单的范围循环: for i in range(n, 2, -1): first, second = second, first + second 现在i将从6变为3而不改变n 。 You first reduce n to 2 or lower ...
  • 我发现了问题的原因。 这是由于Python以及它如何处理不同的编码风格。 它将'\ n'视为新行,因此它以同样的方式处理'\ r'和'\ n'。 因此,当我尝试解码0x0d时,它给出了与0x0a相同的结果。 我能够通过在输入文件的开头指定换行符来解决问题。 input_file = open(input_name, encoding="latin-1", mode="r", newline="") 感谢您对该问题的帮助。 这是唯一的问题,我的代码现在按预期行事。 I found out the cause ...
  • 可能是linecache正在搞乱你并且实际上从上次从类似命名的文件caching该行。 此外,您似乎没有使用完整的文件路径,因此您可能打开的文件不同于您的预期。 例如,您不想使用f_v ,而是要执行以下操作: filepath = os.path.join(, ) 尝试用以下内容替换linecache.getline : def get_line(filename, n): with open(filename, 'r') as f: for ...
  • 我强烈建议你阅读下面的内容,但看起来WriteSpeech停止并关闭stream ,它永远不会重新打开。 这很可能被你的try / except块掩盖了。 while silence: try: input = GetStream(chunk) except: continue 现在说, 尝试从流中读取。 如果有异常,请返回循环顶部。 重复步骤1-2 ad-nauseum 要解决此问题,您可以尝试在except块中重新打开流。 在我试图回答你的问题之前我写的 ...
  • 声明user_name,automatic_name和name_setting变量作为实例变量,你应该没问题 class CameraController: def _init_(self): pass def Picture_Name_Settings(self): pic_name = input("To name the image input N\nTo use automatic naming input A ") pic_name = pic_name.upper() ...
  • 您需要使用self关键字创建Day类的变量属性: class Day: def __init__(self, day): self.day = day self.jobs = {} self.no_jobs = 0 def getjobs(self): """populates a dictionary with the information from an excel sheet""" for i in r ...
  • 问题是你将\2作为字符串传递给kw_correction,而不是collection然后返回\2由正则表达式引擎解析,你可以看到如下: >>> def kw_correction(c_name,kw=h_kw): print(kw,c_name) if c_name.upper() in kw: return "`"+c_name+"`" else: return c_name >>> re.sub(r"(v\[')(.*)('\])", ...
  • 你只是用它来剥离空间。 您可以改为使用正向前瞻来删除紧跟其他所有内容的所有内容: re.sub(r'
    (?=
    )', '', _str) 你可以处理inter
    空格: re.sub(r'
    (?=\s*
    )', '', _str) You're only stripping off spaces following
    with that. You can instead use a positive lookahead to remove all
    s tha ...
  • 您可以读取全局变量,但是如果您希望为它们分配(重新绑定),则需要告诉Python您要使用global关键字。 在这种情况下,根本不需要将这些变量设为全局变量。 您应该将这些属性移动到一个类中。 在这个例子中,我称之为Player import random, time class Player: def __init__(self): self.inventory = ['dagger','torch'] self.hp = 50 self.max ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)