HI,
Is it possible to be able to upload a load of images in one go from a camera, using there file name and saving them in to my database?
I have created a table called images, with fields, image_num and image.
HI,
Is it possible to be able to upload a load of images in one go from a camera, using there file name and saving them in to my database?
I have created a table called images, with fields, image_num and image.
If you have an upload (filefield) in a form, it should be straightforward. However for multiple images, you need multiple filefields. However, there are js/html5/flash apps out there - see http://www.uploadify.com/demos/
i have the following code on my page to use the uploaded_images.php file.
<form action="uploaded_images.php" method="post" >
<p><input type="file" name="uploaded" /></p>
<input type="submit" value="Upload">
</form>
The code on my uploaded_images file is:
<?php
$target = "uploaded_images/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
//This is our size condition
// if ($uploaded_size > 350000)
//{
//echo "Your file is too large.<br>";
//$ok=0;
// }
//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
I have created the uploaded_images folder, but i keep getting the error "Sorry, there was a problem uploading your file." everytime i try to upload an image, what am i doing wrong?
Make sure your directory reference is correct and that your target folder has write permissions. If your code is taken from Tizag's site, then it should work.
Ive now got this working, but is there any way i can get it to upload more than one image at a time?
Some browsers support this:
<form method="post" action="upload.php" enctype="multipart/form-data">
<input name="files[]" id="files" type="file" multiple="" />
</form>
I think Chrome, Safari and Firefox. Not sure about Opera. IE - probably by version 15. I may be wrong.
This is nice though: http://blueimp.github.com/jQuery-File-Upload/
I have this working now, but there is more i need help with :) but i need to post another thread as its not really relating to this one at the moment
Mark this solved then.
I need to change this so it saves the images to the database table i have setup called images.
So rather than upload to "uploaded_images/" they need to upload to my images table, how do i do this?
You mean save image content as blob data? Why? What advantage will this give you?
yes thats what i mean, well i will explain what i need to do.
I have a table on one of my pages which some fields display red depending on the data saved to the database from a previous form. when a field is red i need it to link to the relevant image when clicked.
for example new.php is the page where the info is entered in, these records are saved against each different conveyor number. This page contains some of the following fields (e.g coupling frame, motor frame) and numbers are entered into these. if these fields represent the following coupling frame=1, motor frame=2, the images that will be uploaded are 1 and 2.
so on the fault system matrix page which displays rows (coupling frame, motor frame) and columns with the conveyor numbers, if the fields from the new.php had number entered in then these cells on the fault system matrix page would show red. So i would want these red cells to be able to link the the correct image, so the user can view it.
Hmm. This makes very little sense to me, but I don't see how the 'blob' system outweighs the 'store a path' system.
if these fields represent the following coupling frame=1, motor frame=2, the images that will be uploaded are 1 and 2.
When you say uploaded - what do you mean? Just displayed in the page?
these images will be uploaded to 'uploaded_images/' at the moment, therefore the fault system matrix page needs to be able to link to the relevant image in this folder.
Would it be easier if i sent you the link via private message?
Seeing as this is ongoing - that would be helpful if you don't want the whole world to see it. However, placing a link in the forum would be best as other contributors may be able to help you if I can't.
Here's a quick script for uploading and storing an image and then placing the filename in a db. Note I'm not including any form html. Assume that the file widget is called 'file'. The code is basically http://www.tizag.com/phpT/fileupload.php
if(isset($_FILES['file'])){
$filename = basename($_FILES['file']['name']);
$path_parts = pathinfo($filename);
$filemove = $_FILES['file']['tmp_name'];
//this puts the timestamp into the name so that filenames will be unique
$upload_time = time();
$newfilename = $path_parts['filename'] . "_" . $upload_time . $path_parts['extension'];
$target_path = "uploaded_images/$newfilename";
if(move_uploaded_file($filemove, $target_path)) {
//DB connection details go here...//
//note I don't store path as you'd have to change all the records if you renamed the upload folder for whatever reason
$query = mysql_query("INSERT INTO images SET filename='$newfilename', upload_time = $upload_time"); //any other details you want to add - e.g. from getimagesize() or from other form fields, e.g. description etc.
//test it's successful
} else{
echo "Something broke, please try again!";
}
}
Apologies if you've already got this part working.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.