文件路径插入多行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 theimage
field.
原文:https://stackoverflow.com/questions/36514507
最满意答案
你可能想尝试简单的
if slider_value1 != ''
。 这是一个比if not slider_value1
更好的选项,因为后者将阻止0
,你也可能不想这样做。You might want to try the simple
if slider_value1 != ''
. This is a better option thanif not slider_value1
because the latter will block out0
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 ...