ISSET function to prevent image file overwrites?How can I prevent SQL injection in PHP?startsWith() and endsWith() functions in PHPWhat's the difference between isset() and array_key_exists()?Why shouldn't I use mysql_* functions in PHP?move_uploaded_file failed yet permissions seem right[function.move-uploaded-file]: failed to open stream: No such file or directoryHow to import an SQL file using the command line in MySQL?How to rename uploaded file before saving it into a directory?problems with rand function in php'move_uploaded_file(): Unable to move' Multiple Files XAMPP

How to tease a romance without a cat and mouse chase?

Can a UK national work as a paid shop assistant in the USA?

Can someone get a spouse off a deed that never lived together and was incarcerated?

(For training purposes) Are there any openings with rook pawns that are more effective than others (and if so, what are they)?

Is there an idiom that means that you are in a very strong negotiation position in a negotiation?

Is there a word for pant sleeves?

A nasty indefinite integral

Can the Conjure Barrage spell stack with the Disarming Attack or Trip Attack Battle Master maneuvers?

Palindromic Pan digital Special Square wants you to reveal its Root

Are phenomenological essences experiences that occur in every possible world?

Change to uppercase all tables data

Ribbon Cable Cross Talk - Is there a fix after the fact?

What is this dime sized black bug with white on the segments near Loveland Colorodao?

How do you earn the reader's trust?

Team member is vehemently against code formatting

DeleteCases using two lists but with partial match?

mmap: effect of other processes writing to a file previously mapped read-only

What is the required burn to keep a satellite at a Lagrangian point?

Why A=2 and B=1 in the call signs for Spirit and Opportunity?

What pc resources are used when bruteforcing?

If I arrive in the UK, and then head to mainland Europe, does my Schengen visa 90 day limit start when I arrived in the UK, or mainland Europe?

Shell builtin `printf` line limit?

How to become an Editorial board member?

Way of refund if scammed?



ISSET function to prevent image file overwrites?


How can I prevent SQL injection in PHP?startsWith() and endsWith() functions in PHPWhat's the difference between isset() and array_key_exists()?Why shouldn't I use mysql_* functions in PHP?move_uploaded_file failed yet permissions seem right[function.move-uploaded-file]: failed to open stream: No such file or directoryHow to import an SQL file using the command line in MySQL?How to rename uploaded file before saving it into a directory?problems with rand function in php'move_uploaded_file(): Unable to move' Multiple Files XAMPP






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Im setting up a website like gumtree (uni project). I'm implementing the ability for users to be able to edit their listed items. I'm having trouble with the image part. If the user does not want to change the image when updating other rows, the ran function is overwriting the image with random numbers. I have attached a picture of the code.



I want the user to be able to update things like the product name and price without the image being overwritten by random numbers each time they press the update button.



if(isset($_FILES['uploadimg']['name']))
$ran = rand(0,1000000);
$filename = $_FILES['uploadimg']['name'];
$filename = $ran.$filename;
$filetmp = $_FILES['uploadimg']['tmp_name'];
$filetype = $_FILES['uploadimg']['type'];
move_uploaded_file($filetmp, "../dbimages/".$filename);

$updateimg = "UPDATE elmtree SET path='$filename' WHERE itemid='$id'";
$imageupdate = $conn -> query($updateimg);











share|improve this question
























  • Please post code, errors, sample data or textual output here as plain-text, not as images that can be hard to read, can’t be copy-pasted to help test code or use in answers, and are barrier to those who depend on screen readers. You can edit your question to add the code in the body of your question. For easy formatting use the button to mark blocks of code, or indent with four spaces for the same effect. A screenshot can’t be searched for or run as code.

    – tadman
    Mar 23 at 20:57






  • 1





    Thanks for the advice, I have edited the OP

    – Lux
    Mar 23 at 21:06











  • A hundred times better. Thanks.

    – tadman
    Mar 23 at 21:09






  • 1





    WARNING: Whenever possible use prepared statements to avoid injecting arbitrary data in your queries and creating SQL injection bugs. These are quite straightforward to do in mysqli and PDO where any user-supplied data is specified with a ? or :name indicator that’s later populated using bind_param or execute depending on which one you’re using.

    – tadman
    Mar 23 at 21:09











  • Instead of using random numbers, why not something like a sha256 hash? That's going to be identical for any given file no matter how many times it's uploaded.

    – tadman
    Mar 23 at 21:10

















0















Im setting up a website like gumtree (uni project). I'm implementing the ability for users to be able to edit their listed items. I'm having trouble with the image part. If the user does not want to change the image when updating other rows, the ran function is overwriting the image with random numbers. I have attached a picture of the code.



I want the user to be able to update things like the product name and price without the image being overwritten by random numbers each time they press the update button.



if(isset($_FILES['uploadimg']['name']))
$ran = rand(0,1000000);
$filename = $_FILES['uploadimg']['name'];
$filename = $ran.$filename;
$filetmp = $_FILES['uploadimg']['tmp_name'];
$filetype = $_FILES['uploadimg']['type'];
move_uploaded_file($filetmp, "../dbimages/".$filename);

$updateimg = "UPDATE elmtree SET path='$filename' WHERE itemid='$id'";
$imageupdate = $conn -> query($updateimg);











share|improve this question
























  • Please post code, errors, sample data or textual output here as plain-text, not as images that can be hard to read, can’t be copy-pasted to help test code or use in answers, and are barrier to those who depend on screen readers. You can edit your question to add the code in the body of your question. For easy formatting use the button to mark blocks of code, or indent with four spaces for the same effect. A screenshot can’t be searched for or run as code.

    – tadman
    Mar 23 at 20:57






  • 1





    Thanks for the advice, I have edited the OP

    – Lux
    Mar 23 at 21:06











  • A hundred times better. Thanks.

    – tadman
    Mar 23 at 21:09






  • 1





    WARNING: Whenever possible use prepared statements to avoid injecting arbitrary data in your queries and creating SQL injection bugs. These are quite straightforward to do in mysqli and PDO where any user-supplied data is specified with a ? or :name indicator that’s later populated using bind_param or execute depending on which one you’re using.

    – tadman
    Mar 23 at 21:09











  • Instead of using random numbers, why not something like a sha256 hash? That's going to be identical for any given file no matter how many times it's uploaded.

    – tadman
    Mar 23 at 21:10













0












0








0








Im setting up a website like gumtree (uni project). I'm implementing the ability for users to be able to edit their listed items. I'm having trouble with the image part. If the user does not want to change the image when updating other rows, the ran function is overwriting the image with random numbers. I have attached a picture of the code.



I want the user to be able to update things like the product name and price without the image being overwritten by random numbers each time they press the update button.



if(isset($_FILES['uploadimg']['name']))
$ran = rand(0,1000000);
$filename = $_FILES['uploadimg']['name'];
$filename = $ran.$filename;
$filetmp = $_FILES['uploadimg']['tmp_name'];
$filetype = $_FILES['uploadimg']['type'];
move_uploaded_file($filetmp, "../dbimages/".$filename);

$updateimg = "UPDATE elmtree SET path='$filename' WHERE itemid='$id'";
$imageupdate = $conn -> query($updateimg);











share|improve this question
















Im setting up a website like gumtree (uni project). I'm implementing the ability for users to be able to edit their listed items. I'm having trouble with the image part. If the user does not want to change the image when updating other rows, the ran function is overwriting the image with random numbers. I have attached a picture of the code.



I want the user to be able to update things like the product name and price without the image being overwritten by random numbers each time they press the update button.



if(isset($_FILES['uploadimg']['name']))
$ran = rand(0,1000000);
$filename = $_FILES['uploadimg']['name'];
$filename = $ran.$filename;
$filetmp = $_FILES['uploadimg']['tmp_name'];
$filetype = $_FILES['uploadimg']['type'];
move_uploaded_file($filetmp, "../dbimages/".$filename);

$updateimg = "UPDATE elmtree SET path='$filename' WHERE itemid='$id'";
$imageupdate = $conn -> query($updateimg);








php mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 21:06







Lux

















asked Mar 23 at 20:57









LuxLux

64




64












  • Please post code, errors, sample data or textual output here as plain-text, not as images that can be hard to read, can’t be copy-pasted to help test code or use in answers, and are barrier to those who depend on screen readers. You can edit your question to add the code in the body of your question. For easy formatting use the button to mark blocks of code, or indent with four spaces for the same effect. A screenshot can’t be searched for or run as code.

    – tadman
    Mar 23 at 20:57






  • 1





    Thanks for the advice, I have edited the OP

    – Lux
    Mar 23 at 21:06











  • A hundred times better. Thanks.

    – tadman
    Mar 23 at 21:09






  • 1





    WARNING: Whenever possible use prepared statements to avoid injecting arbitrary data in your queries and creating SQL injection bugs. These are quite straightforward to do in mysqli and PDO where any user-supplied data is specified with a ? or :name indicator that’s later populated using bind_param or execute depending on which one you’re using.

    – tadman
    Mar 23 at 21:09











  • Instead of using random numbers, why not something like a sha256 hash? That's going to be identical for any given file no matter how many times it's uploaded.

    – tadman
    Mar 23 at 21:10

















  • Please post code, errors, sample data or textual output here as plain-text, not as images that can be hard to read, can’t be copy-pasted to help test code or use in answers, and are barrier to those who depend on screen readers. You can edit your question to add the code in the body of your question. For easy formatting use the button to mark blocks of code, or indent with four spaces for the same effect. A screenshot can’t be searched for or run as code.

    – tadman
    Mar 23 at 20:57






  • 1





    Thanks for the advice, I have edited the OP

    – Lux
    Mar 23 at 21:06











  • A hundred times better. Thanks.

    – tadman
    Mar 23 at 21:09






  • 1





    WARNING: Whenever possible use prepared statements to avoid injecting arbitrary data in your queries and creating SQL injection bugs. These are quite straightforward to do in mysqli and PDO where any user-supplied data is specified with a ? or :name indicator that’s later populated using bind_param or execute depending on which one you’re using.

    – tadman
    Mar 23 at 21:09











  • Instead of using random numbers, why not something like a sha256 hash? That's going to be identical for any given file no matter how many times it's uploaded.

    – tadman
    Mar 23 at 21:10
















Please post code, errors, sample data or textual output here as plain-text, not as images that can be hard to read, can’t be copy-pasted to help test code or use in answers, and are barrier to those who depend on screen readers. You can edit your question to add the code in the body of your question. For easy formatting use the button to mark blocks of code, or indent with four spaces for the same effect. A screenshot can’t be searched for or run as code.

– tadman
Mar 23 at 20:57





Please post code, errors, sample data or textual output here as plain-text, not as images that can be hard to read, can’t be copy-pasted to help test code or use in answers, and are barrier to those who depend on screen readers. You can edit your question to add the code in the body of your question. For easy formatting use the button to mark blocks of code, or indent with four spaces for the same effect. A screenshot can’t be searched for or run as code.

– tadman
Mar 23 at 20:57




1




1





Thanks for the advice, I have edited the OP

– Lux
Mar 23 at 21:06





Thanks for the advice, I have edited the OP

– Lux
Mar 23 at 21:06













A hundred times better. Thanks.

– tadman
Mar 23 at 21:09





A hundred times better. Thanks.

– tadman
Mar 23 at 21:09




1




1





WARNING: Whenever possible use prepared statements to avoid injecting arbitrary data in your queries and creating SQL injection bugs. These are quite straightforward to do in mysqli and PDO where any user-supplied data is specified with a ? or :name indicator that’s later populated using bind_param or execute depending on which one you’re using.

– tadman
Mar 23 at 21:09





WARNING: Whenever possible use prepared statements to avoid injecting arbitrary data in your queries and creating SQL injection bugs. These are quite straightforward to do in mysqli and PDO where any user-supplied data is specified with a ? or :name indicator that’s later populated using bind_param or execute depending on which one you’re using.

– tadman
Mar 23 at 21:09













Instead of using random numbers, why not something like a sha256 hash? That's going to be identical for any given file no matter how many times it's uploaded.

– tadman
Mar 23 at 21:10





Instead of using random numbers, why not something like a sha256 hash? That's going to be identical for any given file no matter how many times it's uploaded.

– tadman
Mar 23 at 21:10












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318295%2fisset-function-to-prevent-image-file-overwrites%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318295%2fisset-function-to-prevent-image-file-overwrites%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript