rhs49010 Posted December 4, 2013 Share Posted December 4, 2013 I'm testing this form before adding validation and I can't figure out why the file name comes through as 0 in the banner directory. And it says text/x-generic instead of image/x-generic in the type column, if I highlight the file and click view the image shows. everything in the database is correct and the form is set to enctype=multipart/form-data. Need a set of fresh eyes to look at it, Thanks! <?php $form_complete = FALSE; $imageDirectory = "banners/"; $records = array(); if (isset($_POST['url'], $_FILES ['images'] ['name'], $_POST['expires'])) { $images = $_FILES ['images'] ['name']; $type = $_FILES ['images'] ['type']; $size = $_FILES ['images'] ['size']; $temp = $_FILES ['images'] ['temp_name']; $error = $_FILES ['images'] ['error']; $url = 'url'; $url = preg_match("/\b(??:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $url); $expires = date('M d Y', strtotime('+ $expires days')); $expires = 'expires'; move_uploaded_file($temp,$imageDirectory .$images); //the path to the image file $imagePath = $imageDirectory.$images; $expires = $_POST ['expires']; $url = $_POST['url']; $images = 'banners/'.$_FILES['images']['name']; echo "<p><br /><a href='$url'><img src='$imagePath'/></a><br /> Expires: $expires </p>"; $insert = $db_conn->prepare("INSERT INTO adverts (images,url,expires) VALUES (?,?,?)"); $insert->bind_param('sss', $images, $url, $expires); $insert->execute(); } $form_complete = TRUE; ?> Quote Link to comment https://forums.phpfreaks.com/topic/284524-why-does-the-filename-come-through-as-0/ Share on other sites More sharing options...
.josh Posted December 4, 2013 Share Posted December 4, 2013 well, what type of file extension is it? Quote Link to comment https://forums.phpfreaks.com/topic/284524-why-does-the-filename-come-through-as-0/#findComment-1461254 Share on other sites More sharing options...
rhs49010 Posted December 4, 2013 Author Share Posted December 4, 2013 well, what type of file extension is it? image extension png, gif, jpg. It doesn't matter which I use I get the same name 0 the file is in the banner directory but the name isn't Quote Link to comment https://forums.phpfreaks.com/topic/284524-why-does-the-filename-come-through-as-0/#findComment-1461255 Share on other sites More sharing options...
digibucc Posted December 4, 2013 Share Posted December 4, 2013 i haven't figured it out yet, but since you declared $images anyway, use it on this line instead of $_FILES: any difference? if everything else works and all you need is the uploaded filename, why not use <? $_POST['image_field_name_from_form']; Quote Link to comment https://forums.phpfreaks.com/topic/284524-why-does-the-filename-come-through-as-0/#findComment-1461258 Share on other sites More sharing options...
rhs49010 Posted December 4, 2013 Author Share Posted December 4, 2013 i haven't figured it out yet, but since you declared $images anyway, use it on this line instead of $_FILES: any difference? if everything else works and all you need is the uploaded filename, why not use <? $_POST['image_field_name_from_form']; Maybe I should clarify, inside the banner directory the file name is 0 without the extension and I need the FILE array for validation after I fix this issue. and if I manually change the name to the corresponding image name it works, so that tells me the file is in the directory after the move function puts it there but the name some how gets lost in the shuffle. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/284524-why-does-the-filename-come-through-as-0/#findComment-1461263 Share on other sites More sharing options...
Solution kicken Posted December 4, 2013 Solution Share Posted December 4, 2013 Use var_dump to try and track down where the filename becomes zero at. Nothing in what you posted is jumping out at me as the problem. You can start by dumping the $_FILES array to ensure the original name is intact there, then var_dump the $imageDirectory and $images variables just prior to your move_uploaded_file function call. If the value is 0 there, then go up to the previous place where $image changes and dump it again. Repeat until you've identified the problem line. Quote Link to comment https://forums.phpfreaks.com/topic/284524-why-does-the-filename-come-through-as-0/#findComment-1461269 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.