Help with Adding the Thumbnail path to the Form

I have this working Upload Image Form, that sends the uploaded image to /Upload/:

if ($form_submitted == 'yes') {
$allowedExts = array("gif", "jpeg", "jpg", "pdf", "doc", "docx", "txt", "rtf", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = strtolower( end($temp) );
if (!in_array($extension,$allowedExts) && $_FILES["file"]["name"] != "" )
{
echo ("<div id=\"errorMessage\">Error: Invalid File Name - Allowed File Formats: .doc .docx .gif .jpeg .jpg .rft .png .txt - Please go back and choose another</div>");
}
else if ($_FILES["file"]["size"] >= 100000)
{
echo ("<div class=\"errorMessage1\">Error: Image File Size Exceeds Limit - Go Back - Choose Another Smaller Image File Size</div>");
}
$length = 20;
$randomString = (time());
$thumbnail = $_SESSION['user_id'] . '-' . $randomString . "." . $extension;
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $thumbnail);
$sql = "INSERT INTO videos ( filename ) VALUES( '$thumbnail' )";
mysql_query($sql);
$file_location = website name witheld/upload/
}

I’d like the uploaded image to go to where the thumbnails are stored, but I’m not sure where that is. I know that this code copies the avatar as the video thumbnail:

{
		$sql = "SELECT file_name FROM pictures WHERE user_id = $user_id LIMIT 1";
		$result = mysql_query($sql);
		$row = mysql_fetch_array($result);
		$pic_file = $row['file_name'];
		$output_file = $base_path."/uploads/thumbs/".$file_name_no_extension.'.jpg';
		$input_file = $base_path."/pictures/".$pic_file;
		//echo "Input file = ".$input_file;
		echo " and Output file = ".$output_file."<br>";
		copy($input_file, $output_file);
}
    	@mysql_close();
}

From this code, can you tell me how to add where the thumbnails are stored code, so I to the Upload Image Form?

I’m not entirely sure what you’re asking, and the code is a bit confusing. You say the first script is an image upload script, and indeed the file types allowed suggest that only images, MS-Word documents and text files are allowed, but it then stores the name of the uploaded file in a table called “videos”, which is confusing. The code also uses a variable called $thumbnail, which makes me think that what you’re uploading there is the thumbnail that you want, and so the answer to where they’re stored is in the upload/ folder.

The second script retrieves a filename from the pictures database table, which would lead me to assume that it’s retrieving an image. It then copies that file into the folder /uploads/thumbs/, so presumably that’s the thumbnail folder you’re looking for.

So, are you asking how to modify the first script to automatically copy (or move) the uploaded image into the same folder as the second script copies to? If you just want to put it in a different place, just change this line

move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $thumbnail);

to read

move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/thumbs" . $thumbnail);

But if you look carefully, the first script originally uploads to upload/, where the second one accesses uploads/thumbs/, with an ‘s’ on the end of upload - would this still be correct? I’d have expected the ‘thumbs’ folder would be within the ‘upload’ folder - there’s no hard and fast rule, it just seems more logical to me.

So, if that doesn’t help, come back with a bit more detail on what you need to achieve, your database layout and how that relates to the various things in the two scripts.

ETA - if you’ve looked at many threads on here you’ll know that you also need to be getting around to upgrading from your old-style mysql() calls to use mysqli or PDO functions. Might be worth bearing in mind while you’re in the code anyway.

Thank you

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.