Jump to content

Sprint666l

New Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by Sprint666l

  1. Sorry, I were away from pc, and yeah, I see this problem my bad. I made mistake. if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ $insert = "UPDATE users SET profile_img='$fileName' WHERE username='".$_SESSION['username']."'"; $insert = mysqli_query($connect, $insert); if($insert){ $statusMsg = "The file ".$fileName. " has been uploaded successfully."; }else{ $statusMsg = "File upload failed, please try again."; } }else{ $statusMsg = "Sorry, there was an error uploading your file."; } }else{ $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, & PDF files are allowed to upload.'; } }else{ $statusMsg = 'Please select a file to upload.'; } echo $statusMsg;
  2. I used your broken crystal ball. And I immediately realized that there was a mistake somewhere. I realy dont undestand PDO:: for me its realy hard to know it. 😕 (ironie) I II just used basic php. Thanks for help. Fixed code: if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){ $statusMsg = ''; $targetDir = "images/"; $fileName = basename($_FILES["file"]["name"]); $targetFilePath = $targetDir . $fileName; $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION); // Allow certain file formats $allowTypes = array('jpg','png','jpeg','gif','pdf'); if(in_array($fileType, $allowTypes)){ // Upload file to server if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ $insert = "UPDATE users SET profile_img='$fileName' WHERE username='".$_SESSION['username']."'"; if($insert){ $statusMsg = "The file ".$fileName. " has been uploaded successfully."; }else{ $statusMsg = "File upload failed, please try again."; } }else{ $statusMsg = "Sorry, there was an error uploading your file."; } }else{ $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, & PDF files are allowed to upload.'; } }else{ $statusMsg = 'Please select a file to upload.'; } echo $statusMsg;
  3. Yah, I tried and still doesnt work, but now when I uploaded img new, image it will show in images / (name img.jpg). I need it to be uploaded to the database. Do you know how to fix it ? Because when I uploaded image show it error massage (File upload failed, please try again). I dont know what to do now.
  4. Hello guys, I got problem with this code im still beginer in coding(PDO), so I think, that someone help me with this code. when someone help me I will be realy glad :). this is error massage ->Warning: Undefined array key "file" in C:\xampp\htdocs\forum_2021\account.php on line 63 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\forum_2021\account.php on line 63 <form action="" method="post" enctype="multipart/form-data"> Select Image File to Upload: <input type="file" name="file"> <input type="submit" name="submit" value="Upload"> </form> <?php $statusMsg = ''; // File upload path $targetDir = "images/"; $fileName = basename($_FILES["file"]["name"]); $targetFilePath = $targetDir . $fileName; $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION); if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){ // Allow certain file formats $allowTypes = array('jpg','png','jpeg','gif','pdf'); if(in_array($fileType, $allowTypes)){ // Upload file to server if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ // Insert image file name into database $insert = $connect->query("INSERT into users (profile_img) VALUES ('".$fileName."'"); if($insert){ $statusMsg = "The file ".$fileName. " has been uploaded successfully."; }else{ $statusMsg = "File upload failed, please try again."; } }else{ $statusMsg = "Sorry, there was an error uploading your file."; } }else{ $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, & PDF files are allowed to upload.'; } }else{ $statusMsg = 'Please select a file to upload.'; } // Display status message echo $statusMsg; ?>
×
×
  • 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.