Jump to content

Why does the filename come through as 0


rhs49010
Go to solution Solved by kicken,

Recommended Posts

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;

?>
Link to comment
Share on other sites

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'];
Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.