Help with upload progress bar

Okay, I don’t know why that didn’t work, but I tried several different ideas, none of which are stopping this behavior. Only thing left is to hide the drop zone so they can’t drop another file… This is very odd. I’m not sure if this is even worth messing with, or just leaving it as is. How often do you think users will drag another item on the form while uploading one?

You’re right, let’s leave it at that. Thanks for the help. :slight_smile:

Friend in time of need to upload the gallery to record only once in the “galerias” and the image in “imagens”. The problem is that if I upload two images, the gallery’s records twice in mysql.

upload.php


// Function that writes the gallery.
function gravaGaleria($titulo){
	$sql = mysql_query("INSERT INTO galerias (`id`, `titulo`) VALUES ('', '$titulo')");
}

gravaGaleria($_SERVER['HTTP_X_TITLE']); //

if ($fn) {

	// AJAX call
	file_put_contents(
		'uploads/' . $_SERVER['HTTP_X_TITLE'] . '_' . criptografa($fn) . '.' . extensao($fn),
		file_get_contents('php://input')
	);
	echo "$fn uploaded";
	exit();

}
else {

	// form submit
	$files = $_FILES['fileselect'];

	foreach ($files['error'] as $id => $err) {
		if ($err == UPLOAD_ERR_OK) {
			$fn = $files['name'][$id];
			move_uploaded_file(
				$files['tmp_name'][$id],
				'uploads/' . $fn
			);
			echo "<p>File $fn uploaded.</p>";
		}
	}

}

How do I fix this?

The first thing you should do in gravaGaleria is SELECT COUNT(*) FROM galerias WHERE titulo = ‘$titulo’, check if it returns 0, then INSERT it, otherwise, do nothing.

Secondly, you should use mysql_real_escape_string when passing $_SERVER[‘HTTP_X_TITLE’] to gravaGaleria to prevent SQL Injections.

I did so but did not work:


function gravaGaleria($titulo){
	$sql = mysql_query("SELECT * FROM galerias WHERE `titulo` = '$titulo'");
	if (mysql_num_rows($sql) <= 1)
	{
		$grava = mysql_query("INSERT INTO galerias (`id`, `titulo`) VALUES ('', '$titulo')");
	}
}

gravaGaleria($_SERVER['HTTP_X_TITLE']);

You put <= when you want <. In short, you told it, if you are 1 or 0, insert a record. You only want to insert a record when 0.

The problem is that if the files are very light, they recorded the same time. If I upload two files, record twice.

Now I need to record the id of the gallery in each of the images, but records only the first. See: http://i.imgur.com/mkoAN.jpg


$sql = mysql_query("SELECT * FROM galerias WHERE `titulo` = '".$_SERVER['HTTP_X_TITULO']."'");
	if (mysql_num_rows($sql) == 0)
	{
		$grava = mysql_query("INSERT INTO galerias (`id`, `titulo`) VALUES ('', '".$_SERVER['HTTP_X_TITULO']."')");
		$id = mysql_insert_id();
	}
	$grava_imagens = mysql_query("INSERT INTO uploads (`id`, `galeria`, `imagem`) VALUES ('', '$id', '".$_SERVER['HTTP_X_TITULO'] . '_' . criptografa($fn) . '.' . extensao($fn)."')");

I think this solution has not, right?

You need to grab the pre-existing id.

    $id = null;
    $sql = mysql_query("SELECT id FROM galerias WHERE `titulo` = '".mysql_real_escape_string($_SERVER['HTTP_X_TITULO'])."'"); 
    if (mysql_num_rows($sql) == 0) 
    { 
        $grava = mysql_query("INSERT INTO galerias (`id`, `titulo`) VALUES ('', '".mysql_real_escape_string($_SERVER['HTTP_X_TITULO'])."')"); 
        $id = mysql_insert_id(); 
    } 
    else
    {
      $row = mysql_fetch_assoc($sql);
      $id = $row[0]['id'];
    }
    $grava_imagens = mysql_query("INSERT INTO uploads (`id`, `galeria`, `imagem`) VALUES ('', '$id', '".mysql_real_escape_string($_SERVER['HTTP_X_TITULO']) . '_' . criptografa($fn) . '.' . extensao($fn)."')");  

It worked, the only problem now is that I quoted earlier.

The problem is that if the files are very light, they recorded the same time. If I upload two files, record twice.

If I upload two files the same size, two galleries will be recorded.

I would also allow them to be crisdas galleries with the same name. What do you suggest?

The best option is to run the uploads synchronously. So that two photos couldn’t be uploaded at the exact same time. Which can be done by changing your JavaScript to

xhr.open("POST", $id("upload").action, false);

So is bad, because all the progress bars are filled at the same time, the end of the process.

When doubts about the title, any suggestions?

I would also allow them to be created galleries with the same name. What do you suggest?

The multiple categories with the same name will be a problem and your code actually won’t support it, it will put the images in the category that already has that name.

As for how to prevent the duplicate category names from being recreated, I’m still thinking about it and would suggest posting a new thread in the PHP forum about it. As you will get more responses there.

The question of the title was pretty easy to solve. I took the session_id () in the upload page and went to the upload.php (I think with md5 () is better, right?).

All that remains is to solve that problem of files with the same size, which are upados simultaneously and create the gallery twice. = /

Friend, you can help me replace my progress bar for that in CSS? http://lab.galengidman.com/progress-bars/

Hey Felipe, I am sure I can help you achieve that, however, I am out of town this weekend so my resources are very limited. I should be able to devote more time on Monday when I return.

Thank you. :slight_smile:

I’ll be grateful if you could help me with this other problem too. :slight_smile: http://www.sitepoint.com/forums/showthread.php?871227-Resize-image-returns-black-image

The problem of image resizing is resolved. I did not realize that was generating the md5 several times. :slight_smile:

Now I need to customize the progress bar only.