0

Hello,

I have developed a form which containts to input type files option 1 is for downloadable file and second one is for features image but the problem is that image name is saving into the database but second file is not moving into the database

<input type="file" name="ft_img" style="margin: 0 !important;"/> <input type="file" name="download" style="margin: 0 !important;"/>

$imgname1 = $_FILES["ft_img"]["name"];
        $imgtype1 = $_FILES["ft_img"]["type"];
        $imgtemp1 = $_FILES["ft_img"]["tmp_name"];

        $path1 = "./uploads/".$imgname1;

        $download  = $_FILES["download"]["name"];
        $file_type = $_FILES["download"]["type"];
        $file_temp = $_FILES["download"]["tmp_name"];

        $file_path1 = "./uploads/".$download;
        move_uploaded_file($file_temp, $file_path1);

        $title     = $_POST["title"];
        $descrip   = mysqli_real_escape_string($connect, $_POST["descrip"]);
        $android   = $_POST["android"];
        $iphone    = $_POST["iphone"];
        $catname   = $_POST["catname"];
        $parent    = $_POST["parent"];
        $fetch     = $_POST["fetch"];

        move_uploaded_file($imgtemp1, $path1);
2
Contributors
3
Replies
18
Views
2 Years
Discussion Span
Last Post by minitauros
1

I've cleared up some code for you as it seems to be in random order. Try this out and let us know what the debug messages say, as your code does not appear to be wrong at first glance.

<input type="file" name="ft_img" style="margin: 0 !important;"><input type="file" name="download" style="margin: 0 !important;">

<?php
// Image 1
$imgname1 = $_FILES["ft_img"]["name"];
$imgtype1 = $_FILES["ft_img"]["type"];
$imgtemp1 = $_FILES["ft_img"]["tmp_name"];
$path1 = "./uploads/".$imgname1;
$status = move_uploaded_file($imgtemp1, $path1);

// Debug image 1:
printf(
    'Image 1 should have been moved from %s to %s. $status = %s',
    $imgtemp1,
    $path1,
    $status ? 'true' : 'false'
);

// Image 2 (download)
$download  = $_FILES["download"]["name"];
$file_type = $_FILES["download"]["type"];
$file_temp = $_FILES["download"]["tmp_name"];
$file_path1 = "./uploads/".$download;
$status = move_uploaded_file($file_temp, $file_path1);

// Debug image 2:
printf(
    'Image 2 should have been moved from %s to %s. $status = %s',
    $file_temp,
    $file_path1,
    $status ? 'true' : 'false'
);

By the way, you do not need to add !important to inline style tags, as inline CSS always overrides existing CSS rules.

Edited by minitauros

0

Image 1 should have been moved from C:\wamp\tmp\phpB61F.tmp to ./uploads/fg_6.jpg. $status = true

Image 2 should have been moved from C:\wamp\tmp\phpB620.tmp to ./uploads/ennio_morricone-the_good_the_bad_the_ugly.mp3. $status = true

This was the output I got and the problem solved though but I dont know why this is not working as I just place copy() function and it worked for me

0

Well if you want to hear why it didn't work, I think we need some more code of you to review, but if you have it working and if you're happy with that, I'm happy too :).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.