Thanks for that quick reply. I have settings on the uploaded_files folder at 777. When I don't add the sql code, everything works. This error only occurs when I add the sql code shown above.
I have been referring to your image upload article/tutorial.
This part of code is where you give the file a unique name before it is uploaded to the directory. You used a $now variable to get the time and date in your article i believe.
I have created a counter to add to each filename when uploaded so each image i upload for example appear slike "photo1" "photo2" and so on...
The code above adds the counter variable to the beginning of the uploaded filename, which looks like "1photo" "2photo" when uploaded, but is there anyway of adding the counter variable to the end of the filename variable. I have tried to alter the code many times but have been unsuccessful so far. All i seem to get is a parse error when i move the .$counter. to the end of the line.
It's because the filename also includes the file extension. So you're basically making a picture.jpg2 which is creating a parse error. What you may have to do is split the filename by "." and insert a $counter."." in between the two resulting strings.
It's because the filename also includes the file extension. So you're basically making a picture.jpg2 which is creating a parse error. What you may have to do is split the filename by "." and insert a $counter."." in between the two resulting strings.
If you want to retain the filename but check there is no collission you could do something like this:
i just added this in the upload.processor page after the upload code, right before redirecting to .sucess. works fine for me. $year and $month are variable i added to the upload.form page.
Yeh thats correct, i need the original filename of the image that is being uploaded with a counter variable being added onto the end of the filename not before as the post above your last states
example
filename = photo.jpg
new filename = photo1.jpg and so on...
basically all the images i upload are ging to be called photo but i need a way of adding them so they are not duplicated so they are all individual, which makes it an easy way for me to know how many images i have uploaded
photo156 being the 156th image i have uploaded kinda thing lol
Yeh thats correct, i need the original filename of the image that is being uploaded with a counter variable being added onto the end of the filename not before as the post above your last states
Which I am trying to pass from multiple.upload.form.php file.
I did echo on these values on multiple.upload.form.php and it outputs the correct values. Did I pass these values along wrong? Here is the code I am using right now in the multiple.upload.processor.php:
Code:
// now let's move the file to its final and allocate it with the new filename
foreach($active_keys as $key)
{
@move_uploaded_file($_FILES[$fieldname]['tmp_name'][$key], $uploadFilename[$key])
or error('receiving directory insuffiecient permission', $uploadForm);
}
// my code additions
$hardwareId = $_POST['hardwareId'];
$modelId = $_POST['modelId'];
$brandID = $_POST['brandID'];
echo $uploadFilename;
$query = "INSERT INTO model_images VALUES ('', '$modelId', '$uploadFilename', '$hardwareId', '$brandID')";
if (!($result = @ mysql_query ($query,$connection))) showerror;
echo $query;
//end my code additions
// If you got this far, everything has worked and the file has been successfully saved.
// We are now going to redirect the client to the success page.
header('Location: ' . $uploadSuccess);
Here is the code I added into mutiple.upload.form.php:
Code:
// set a max file size for the html upload form
$max_file_size = 1200000; // size in bytes
echo "Brand ID is " . $brandID . "\n";
echo "Model ID is " . $modelId . "\n";
echo "hardware ID is " . $hardwareId . "\n";
$_POST['brandID'];
$_POST['modelId'];
$_POST['hardwareId'];
$brandID = $_POST['brandID'];
$modelId = $_POST['modelId'];
$hardwareId = $_POST['hardwareId'];
// now echo the html page
Here is the code to the page that sends this page the brandID, modelId, and hardwareId values (this i know works because it echo's the correct values at the top of multiple.upload.form.php):
Code:
<?php
#####################################################################
include 'db.php'; //This calls on the database info
include 'error.php'; // this calls on the error function
#####################################################################
#####################################################################
// echo $_POST['brandID']; // To see if the brandID is being passed correctly, simply uncomment this code and view the site
#####################################################################
#####################################################################
$brandname = $_POST['brandname'];
$hardware = $_POST['hardware'];
#####################################################################
#####################################################################
// this code retrieves the information from the database, and passes it along to be printed
$query = "SELECT bn.brand_title,
sai.model_number,
sai.description,
sai.manufactured_origin,
sai.wood_case,
sai.weight,
sai.model_id_number,
bn.brand_id_number,
h.hardware_name,
h.hardware_id
FROM hardware h, brand_name bn, stats_and_info sai, brand2model2type bmt
WHERE sai.description != \"\"
AND bmt.brand_id = bn.brand_id_number
AND bmt.hardware_id = h.hardware_id
AND bmt.model_id = sai.model_id_number
AND bn.brand_id_number = $brandname
AND bmt.hardware_id =$hardware
ORDER BY h.hardware_name ASC LIMIT 100";
//end the code that retriieves the info from the database
#####################################################################
// Open a connection to the DBMS
if (!($connection = @ mysql_connect($hostname,
$username,
$password)))
die("Could not connect to database");
if (!mysql_select_db($databasename, $connection))
showerror( );
// Run the query created above on the database through
// the connection
if (!($result = @ mysql_query ($query, $connection)))
showerror( );
echo "\n<table border=\"0\">";
// Process the INFO
while ($row = @ mysql_fetch_array($result))
{
// Print a heading for the Information
echo "\n<tr>\n\t<td bgcolor=\"maroon\">" .
"<b><font color=\"white\">" .
$row["brand_title"] . " " .
$row["model_number"] . " " .
$row["hardware_name"] . " ";
echo "</td>\n</tr>";
// Below makes a link to where more info can be found on a specific brand+model+type
echo "<tr align=\"right\"><td>" .
"<a href=\"multiple.upload.form.php?brandID=" . $row["brand_id_number"] . "&modelId=" .
$row["model_id_number"] . "&hardwareId=" .
$row["hardware_id"] .
"\">Click Here to upload images for this model number</a>" .
"</td></tr>";
// Blank row for better looks
echo "\n<tr>\n\t<td></td>\n</tr>";
}
echo "\n</table>\n";
if (!mysql_close($connection))
showerror( );
?>
The one thing I know for sure is that the values hardwareId, modelId, and brandID pass successfully up to the multiple.upload.form.php file.
Sorry for the lengthy post, trying to provide as much information as possible.
Hello. A friend helped me out and I was able to get this working. THe problem was that $uploadFilename is an array. The code I found on this forum must have been for the single.upload code.
Those variables are id numbers for an items brandname, model name, and hardware type. The site I am doing is a list of vintage audio pieces.
If anyone has any questions on what I did, please pm me and I will certainly try to help out. Thanks for the help you guys provided, and the great code! I am now going to try and change the $uploadFilename array's path to only reflect the image name so that I can call on the database to display the images.
Andy
Bookmarks