Jump to content

Recommended Posts

So I was able to return the data ok with this

<?php
$path = "./";
$files = "*.gif";
        
$sfiles = glob($path.$files);
asort($sfiles);

foreach ($sfiles as $filename) {
   echo "<br>\n", "$filename " . filesize($filename);
}
?> 

 

I could use assistance assigning the information variables that can then be uploaded to the database. My table consists of this so far and Im not sure if this is the proper way to store the data.

  • name varchar(100) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext
  • size int(11) Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext
  • type varchar(20) latin1_swedish_ci Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext
  • content mediumblob BINARY Yes NULL Browse distinct values Change Drop Primary Unique Index Fulltext

Made som eprogress but need help with variables

Heres what I have now that kind of works

<?php
$path = "./";
$files = "*.gif";
$name = '$filename'; //Variable here
$size = 'size';          //Variable here
$type = 'type';        //Variable here
        
$sfiles = glob($path.$files);
asort($sfiles);

foreach ($sfiles as $filename) {
   echo "<br>\n", "$filename " . filesize($filename);
}
$content = file_get_contents($filename);
if ($conn = mysqli_connect('localhost', 'root', 'xxx', 'xxx')) {
		$content = mysqli_real_escape_string($conn, $content);
		$sql = "insert into images (name, size, type, content) values ('{$name}', '{$size}', '{$type}', '{$content}')";

		if (mysqli_query($conn, $sql)) {
			$uploadOk = true;
			$imageId = mysqli_insert_id($conn);
		} else {
			echo "Error: Could not save the data to mysql database. Please try again.";
		}

		mysqli_close($conn);
	} else {
		echo "Error: Could not connect to mysql database. Please try again.";
	}
?> 

 

But this adds a file to the table with $filename 0 size and no type. I am having defining the variable correctly

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.