Uploaded image name need to change [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
After Uploading image it shows date in the name of image in uploadfolder.Instead
need to show ward number which is posted in $ward.The commentline was i changed
but its not working.please help me.
$image_name = "img_"."_".date("Y-m-d-H-m-s").".png";
// $image_name = "img_"."_".$ward.".png";

Try following code
$ward = $_POST['ward'];
$tmp_name = $_FILES["image"]["tmp_name"];//name of your input file name
$uploads_dir = "Your Upload idrectory path";
$image_name = "img__".$ward.".png";
move_uploaded_file($tmp_name, "$uploads_dir/$image_name");

The image name should have the ward name so that the saved file will have the same name. U need to get the ward name in some variable say $ward which is posted from the form, then add this $ward as an extension to the image name.
$ward = $_POST['ward'];
$uploads_dir = "";//path where the image needs to be stored in ur computer
$image_name = "img_".$ward.".png";
Try this code snippet in the original code and the extension of the image will be changed

Related

image from database phpmyadmin [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
I have a little problem I try to display a url image that there is in my phpmyadmin database, but nothing is displayed. I am trying to display an image from my database. I put you my code and my line of the database. Thank you in advance for your help !
see if I made a mistake in the code, or if I used the wrong path
the URL of my image is called "img_l" in my database and it is in a category called "liste"
Voici mon code :
<?php
$bdd = new PDO('mysql:host=localhost;dbname=animebd;chaset=utf8','root','');
$req = $bdd->query('SELECT img_l,nomL FROM liste');
while($donnees = $req->fetch()){
echo('<img style="width:50px;height:50px;border-radius;:500px;" img_l = "' . $donnees['img_l'] . '"/><br/>');
}
?>
In image tag, you don't have src attribute. You must add it and concatenate your data from db with images directory.
$path = './public/images/' . $donnees['img_l'];
of course my answer is valid only if $donnees['img_l'] is the filename with extension (mycar.jpg)

Problem with adding image files to my server [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Basically, I am trying to put an image file into a folder in my server and add the dir in MYSQL BD. It successfully puts the file into the folder and adds the path link to the row in the table.
Now, the problem: when I try to download the file and show it, it downloads but nothing shows, so I check the file in the FTP and it turns out the file size is 0.1kb. What am I doing wrong and how do I fix it?
I've done some research on the issue and I might be crazy but I think I'm the only one having this issue because I couldn't get help anywhere.
here's my code;
$ImageData = $_POST['image_data'];
$ImageName = date("D M d, G:i");
$ImagePath = "albums/$ImageName.jpg";
$UploadPath = __DIR__."/../".$ImagePath;
$img = $ImagePath; //to be inserted into DB row
//mysql ("INSERT INTO table...") query here
if($InsertSQL->rowCount()){
file_put_contents($UploadPath,base64_decode($ImageData));
// file_put_contents($UploadPath,$ImageData);
echo "Your Image Has Been Uploaded.";
}
N/B: I use base64_decode because I encoded it from android.
I expect the file to save to the server dir with the actual size.
Files are stored in $_FILES not $_POST.
Assuming that the field in your form is called image_data
$ImageTmpPath = file_get_contents($_FILES['image_data']['tmp_name']);
$ImageName = date("D M d, G:i");
$ImagePath = "albums/$ImageName.jpg";
$UploadPath = __DIR__."/../".$ImagePath;
$img = $ImagePath; //to be inserted into DB row
//mysql ("INSERT INTO table...") query here
if($InsertSQL->rowCount()){
file_put_contents($UploadPath,base64_decode($ImageTmpPath));
echo "Your Image Has Been Uploaded.";
}
So thanks to #RiggsFolly and #Rust, files are actually stored with $_FILES not $_POST
but what actually solved my issue was the
file_put_contents($UploadPath,base64_decode($ImageData));
it is supposed to be
move_uploaded_file(base64_decode($ImageTmpPath),$UploadPath);

How to assign a value to a variable from a text file? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am using a script to back up files from ftp. code is below.
include "recurseZip.php";
//Source file or directory to be compressed.
$src='source/images/black.png';
//Destination folder where we create Zip file.
$dst='backup';
$z=new recurseZip();
echo $z->compress($src,$dst);
Now I want to get values to $src from source/files.txt which contains a list of file names.
My .txt file:
index.php.bk-2013-12-02
index.php.bk-2013-12-07
index.php.bk-2013-12-10
index.php.bk-2013-12-20
index.php.bk-2013-12-26
function.php.bk-2013-12-20
function.php.bk-2013-12-23
contact.php.bk-2013-12-23
contact.php.bk-2013-12-30
my source/files.txt contains 10 file names those need to be assigned as values to the variable $src I am using this script http://ramui.com/articles/php-zip-files-and-directory.html
how can I do that.?
any help will be very much appreciated.
Thanks.
Okay, you want to get the file name from each line of the .txt file.
<?php
$myFile = "files.txt";
$lines = file($myFile);
foreach($lines as $line){
$file = basename($line);
echo $file;
}
?>
Answer to your old question variant
You can use the basename() function. The manual says, "given a string containing the path to a file or directory, this function will return the trailing name component".
Now, you said "I want to get file name to $src from source/files.txt", so assuming from this, you are looking to get the file name i.e. black.png. This could be achieved using the basename() function as mentioned before.
<?php
$src='source/images/black.png';
$file = basename($src);
echo $file;
?>
Output
black.png
http://ideone.com/p2b4sr

how to upload file into a desired folder in php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
i want the name of the image to be saved in database and the file to be save into a folder of my choice. the image name is setting saved into database but the problem is that i am unable to upload the image into a folder. so please help.
This is the code i am using.
mysqli_query($con,"INSERT INTO blog (title, image, content)
VALUES ('$_POST[title]', '$_POST[image]','$_POST[content]')");
$target_Path = "uploaded/";
$target_Path = $target_Path.basename( $_FILES['image']['name'] );
move_uploaded_file( $_FILES['image']['tmp_name'], $target_Path );
Use absolute path like this :
$target_Path = "/var/www/html/uploaded/";
$target_Path = $target_Path.basename( $_FILES['image']['name'] );
move_uploaded_file( $_FILES['image']['tmp_name'], $target_Path );

I need to change video file extensions to mp4 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'd really appreciate someone doing this and also explaining what they did so I can understand it better.
Current Code:
$name = $_FILES['file']['name'];
$extension = strtolower(substr ($name, strpos($name, '.') + 1));
$newextension = 'mp4';
$type = $_FILES['file']['type'];
$temp = $_FILES['file']['tmp_name'];
$location = 'thelocation';
if ($extension!==$newextension)
{
$extension = $newextension;
And if this can not be done, can someone inform me of a method on how to convert all none .mp4 files into .mp4 files serverside and if it is a automatic method or will have to be done manually.
Remember that you're working with a temporary file, that needs to be copied from your temp directory to a final location such as /videos/video.mp4.
So you'd change the extension as soon as you copy the file to the final location.
First, you'd best use the pathinfo() function for retrieving the extension:
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
Then, you'd filter the old extension from the filename, and append the new extension:
$newfilename = basename($_FILES['file']['name'], $extension).$newextension;
Edit: instead of substr and strrpos, I've now used basename() with the extension as a suffix to retrieve the filename, which makes the code shorter and more readable.
And copy the file to its new location:
copy($_FILES['file']['tmp_name'], 'full/path/to/your/videos/'.$newfilename);

Categories