Jump to content
#StayAtHome ×


New Members
  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About Stusara

  • Rank
  1. Excuse my longwinded reply .. pretty new to this
  2. Just a name change on the image so it doesn't overwrite the file if someone uploads the same named file. I have seen some code that does this and adds numbers to the file name which would be handy i.e image01.png image02.png etc
  3. Stusara

    Hi :)

    Hi All... My name is Stu... Im from the UK. Ive built a few sites over the years on CMS and years ago i thought i'd have a dabble with dreamweaver... Although sometimes it frustrates the hell out of me and I sit up for hours on end trying to get something working the end achievement is second to none! Today i have been searching high and low for something i know should work but just can't find the answer so... Its time to ask some experts... Hopefully i can learn from some of my mistakes and I won't have to sit here for so long! Im hoping to speak to some of you soon through the forum as I'm looking for a few answers! All the best Stuart
  4. Hi Im trying to put a link on to upload an image.. I have the code and its working fine.. BUT.. i want to change it slightly so the image file is changed so it does not give the error "Sorry, file already exists." i manage to remove this but then it just over writes the existing image... Can some one help with a simple piece of code that will change the image file name on upload even if its just a number after the file name will suffice... Here is my current code: thanks in advance! Stu <?php $target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 10000000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if ( move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "upload/".$username.".".$extension)) { echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } ?>
  • 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.