Jump to content

file upload help .... (.)(.)


imarockstar

Recommended Posts

I ahve a little script that uploads a file ... here is the code ... it works .. but i need it to skip over the updating of the image name if there was no file uploaded ... everything works great, but if no image is uploaded it ofcourse puts nothing in the DB which causes the image to display as nothing is there ...

 

all my variables are above this code in the file .. but i wont waste time typing them ...

 

if ($_POST['updatemerch'])
{


$newname = uniqid("whc").".jpg";
move_uploaded_file($_FILES['mimage']['tmp_name'],
"../images/merch/$newname");

$mimage = $newname;



mysql_query("UPDATE merch SET userid = '$userid', bid = '$bid', mcat = '$mcat', mname = '$mname', mquantity = '$mquantity', msmall = '$msmall', mmedium = '$mmedium',  mlarge = '$mlarge' , mcost = '$mcost', mprice = '$mprice', mdesc = '$mdesc', mimage = '$mimage'  WHERE mid = '$mid' ");

header("Location: ../view_merch.php");
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/175390-file-upload-help/
Share on other sites

but i wont waste time typing them ...

 

You should try copy and paste... I hear it is pretty awesome ;)

 

How about right before your query you do something like

 

if($mimage == "") {
$mimage = 'defaultimage.jpg';
}

 

so it inserts whatever you want?

Link to comment
https://forums.phpfreaks.com/topic/175390-file-upload-help/#findComment-924392
Share on other sites

if (move_uploaded_file($_FILES['mimage']['tmp_name'], "../images/merch/$newname")){
$mimage = $newname;
mysql_query("UPDATE merch SET userid = '$userid', bid = '$bid', mcat = '$mcat', mname = '$mname', mquantity = '$mquantity', msmall = '$msmall', mmedium = '$mmedium',  mlarge = '$mlarge' , mcost = '$mcost', mprice = '$mprice', mdesc = '$mdesc', mimage = '$mimage'  WHERE mid = '$mid' ");
header("Location: ../view_merch.php");
}

Link to comment
https://forums.phpfreaks.com/topic/175390-file-upload-help/#findComment-924393
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.