Hi everyone, I have another question, im uploading an image to my ftp, and the name of it to MYSQL Database. I need to get the .jpg or .gif, how do I do that? Heres my code: $number = "1"; $new_name = $car_name . "" .$number; $upload = move_uploaded_file($_FILES['pic1']['tmp_name'], $images_path . "/" . $new_name); // Upload the file if ($upload) { // If the file was echo "works"; } Code (markup):
<?php $number = "1"; $new_name = $car_name . "" .$number; $upload = move_uploaded_file($_FILES['pic1']['tmp_name'], $images_path . "/" . $new_name); // Upload the file if ($upload) { // If the file was printf('%s uploaded, it\'s extension is \'%s\'<br />', $images_path . "/" . $new_name, end( split('\.', $new_name ) ) ); } ?> PHP:
It still does not give me the .jpg, here is what it prints: ..../public_html/car_pics/pimpride1 uploaded, it's extension is 'pimpride1' the name of the file was pimpride1 but it didnt get pimpride1.jpg Do you know why? Thanks!
well I don't have all the information available because you didnt post the whole script, I assumed $new_name would contain the filename and extension, it seems it only contains the filename and number
$number = "1"; $new_name = "$car_name$number." . end(explode('.', $_FILES['pic1']['name']); $upload = move_uploaded_file($_FILES['pic1']['tmp_name'], $images_path . "/" . $new_name); // Upload the file if ($upload) { // If the file was echo "works"; } PHP:
Don't use the tmp_name to get the file extension, because it'll be different that the original one. Use $_FILES['pic1']['name'].
It's what happens when you are lazy and copy paste and then forget to change it... But you were not supposed to see that, I edited that a few seconds after I posted
move_uploaded_file($_FILES['pic1']['tmp_name'], $images_path . "/" . $new_name); PHP: Is this method from PHP?