I was just working on my PHP website and I need database for that, so I was trying to insert image path to phpMyAdmin.
But I am unable to add path because I don't know the exact syntax for image path and also when I am trying to insert image path.
I can't see empty column instead of that. I am watching something like binary and choose file, as you can see in image.
Its good to save files / images in folders and just save their name in database.
<input type="file" name="photo">
$tmpFile = $_FILES['file']['tmp_name'];
$newFile = $_FILES['file']['name'];
move_uploaded_file($tmpFile, '/images/'.$newFile);
$query = "update users set photo = '$newFile' where id = '$userId'";
Here I assume that we are going to upload profile photo of users and saving file in images folder. Also, updating file name in database record.
Related
I have runned into a problem with my code. I have uploaded my images into the database as a BLOB and also moved my image as an image with a unique ID or in my scenario like this {{ img/5e0a5f121e4468.89602240.jpg }}. Now what i am trying to do is delete the image from database and also in the same time unlink the image which has this unique ID . Here Below i have the code that submits the form in the database with the image :
if (isset($_POST['submit'])) {
include "conn.php";
$imgOne=$_FILES['pictureOne'];
$fileName=$imgOne['name'];
$fileTmpName=$imgOne['tmp_name'];
$fileSize=$imgOne['size'];
$fileError=$imgOne['error'];
$fileExt=explode('.',$fileName);
$fileExt=strtolower(end($fileExt));
$newFileName=uniqid('',true).'.'.$fileExt;
$path='C:/xampp/htdocs/img/'.$newFileName;
if(move_uploaded_file($fileTmpName,$path)){
$query="INSERT INTO images(pictureOne)
VALUES('$newFileName')";
mysqli_query($conn,$query);
};
};
In the other file where i preform the deletion of the image from the databse is this :
include 'conn.php';
$id=$_GET['id'];
$queryD="DELETE pictureOne FROM posts WHERE id='$id'";
$resultD=mysqli_query($conn,$queryD);
Now please if you could help me out how would i unlink the image from my image folder since the problem for me is this unique ID which i can wrap mu head around.
Thank you alot for the help.
If I understand what you correctly, you are storing the file with a particular unique name and then storing that file name in the database. Later on, you want to remove the row from the database and delete the file.
First, select the row from the table so that you can get the name of the file that you originally stored. Delete the row from the database. Delete the file.
I stored a picture in the uploads folder of my laravel project, I have an image table that has column name filename as a string type, how can i save the uploaded image location in the filename column and then output in my photos blade file based on the file location in my db
This is the code I used to store my image in my uploads folder
$filename = $file1->getClientOriginalName();
$picture = date('His').$filename;
$file1->move($destinationPath, $picture);
Below is the steps I did regarding upload and retrieve user related images.
For the example, a user upload his profile picture which named myfile.png
So, for upload:
Get the file from $request
Get the file name with getClientOriginalName() (i.e. myfile) and also the file extension with getClientOriginalExtension() (i.e. .png)
Generate some random strings which will be appended to the file name to avoid file name duplication (i.e. fx7ew6)
Append the original file name with the generated random strings along with the extension (i.e. myfile_fx7ew6.png)
Save image file to folder (i.e. public/img) and also save the file name to the database
For retrieve:
You can use <img src="/img/{{FILE_NAME}}"> to show the uploaded image which will result <img src="/img/myfile_fx7ew6.png"> IF you upload the image to public/img.
I want to ask, if I have a web form, and people use it to upload something to my db. If 2 persons uploaded the same file with the same name, in the uploads directory, one of them will replace the other. So I need to change the name of every file uploaded to db to : filename201405051200.pdf or jpg or...
Here we have the filename per example image1 and the numbers are the date and time of the uploads. So any help. I am using the code shown as an answer in the link below:
Uploading blob files/images into Mysql
I used this code:
$path = "../uploads/".$_FILES['file']['name'];
if(move_uploaded_file($_FILES["file"]["tmp_name"], $path.'_'.time())){
...
}
but now the format type of the file is replaced by the time. So if it is img.jpg it is now img85890338jpg and wont open properly
You can use pathinfo to extract the file extension:
$fileExt = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
After that you can create your new file name:
if(move_uploaded_file($_FILES["file"]["tmp_name"], $path.'_'.time().date().'.'.$fileExt)) {
}
I wonder how I do to save the name of an image in mysql with plupload?
In file upload.php have many variables and I do not know which one stores the filename, already tried everything and could not
I would like to save the image name that plupload creates, not the original name
can someone help me?
thank you
Get the file name like this.
$filename = $_FILES["file"]["name"];
and pass $filename into insert statement.
Try this plugin for plupload to upload file from github
You can directly used a $fileName variable
here give you a example, like
$sSQL = "INSERT INTO eletz_multiimage (image_name) VALUES ('$fileName')";
$result = mysql_query($sSQL);
I am using library to upload multiple images in php .This library use flash file and a php file . All things are working but problem is that I want to run a query after each image is uploaded to store image detail in database . If i write query in php file after uploading code then It upload images but no error given and no image details are put in database.
Can any one help me that how I add image details in database after uploading image using flash uploader
This is my code
<?
extract($_GET);
$filename = $_FILES['Filedata']['name'];
$temp_name = $_FILES['Filedata']['tmp_name'];
$error = $_FILES['Filedata']['error'];
$size = $_FILES['Filedata']['size'];
/* NOTE: Some server setups might need you to use an absolute path to your "dropbox" folder
(as opposed to the relative one I've used below). Check your server configuration to get
the absolute path to your web directory*/
if(!$error){
copy($temp_name, '../dropbox/'.$filename);
$news_query="insert into tbl_news(img_id,headline,caption,news_catgory_id,shooting_date) Values('0000','News_Headline','News_Caption',
'New_Category','now()')";
mysql_query($news_query) or die(mysql_error());
}
?>
all code working but query data is not updated in database
May be it's a sql error...if your "shooting_date" field is numeric or date, you can't set it's value like this: 'now()', you must strip the quotes.