Jump to content

Notice: Undefined index


alexandruwks

Recommended Posts

<?php

require_once('connect.php');
if(isset($_SESSION['username']) & !empty($_SESSION['username'])){
$fileName = $_FILES["uploaded_file"]["name"]; $fileTmpLoc =
$_FILES["uploaded_file"]["tmp_name"]; $fileType =
$_FILES["uploaded_file"]["type"]; $fileSize =
$_FILES["uploaded_file"]["size"]; $fileErrorMsg =
$_FILES["uploaded_file"]["error"]; $data = date("Y-m-d-H-i-s");

$nr= rand(1, 30); $kaboom = explode(".", $fileName); $fileExt =
end($kaboom); if (!$fileTmpLoc) {
echo "";
exit(); 
} else if($fileSize > 15242880) {
echo "Imagine > 15MB";
unlink($fileTmpLoc); 
exit(); 
} else if (!preg_match("/.(gif|jpg|jpeg|png)$/i", $fileName) ) {

echo "Format permis gif/png/jpeg/jpg";
unlink($fileTmpLoc); 
exit(); 
} else if ($fileErrorMsg == 1) {
echo "Incercati din nou";
exit(); 
}
$moveResult = move_uploaded_file($fileTmpLoc, "galerie/uploads/$nr$username.jpeg");

if ($moveResult != true) {
echo "Fisierul NU a fost incarcat";
unlink($fileTmpLoc); 
exit(); }

include_once("ak_php_img_lib_1.0.php"); $target_file =
"galerie/uploads/$nr$username.jpeg"; $resized_file =
"galerie/uploads/r$nr$username.jpeg"; $edit_target =
"$nr$username.jpeg";
$wmax = 300;
$hmax = 300;

ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
$_SESSION['editname'] = $edit_target;
header("Refresh:0"); 
exit(); 
} else {
session_destroy(); 
require "../login.php"; 
} 
?>
Until upload a file, I recived this errors:

 

Notice: Undefined index: uploaded_file in E:\LICENTA\xampp\htdocs\licentaCC\galerie\image_upload_script.php on line 42

Notice: Undefined index: uploaded_file in E:\LICENTA\xampp\htdocs\licentaCC\galerie\image_upload_script.php on line 43

Notice: Undefined index: uploaded_file in E:\LICENTA\xampp\htdocs\licentaCC\galerie\image_upload_script.php on line 44

Notice: Undefined index: uploaded_file in E:\LICENTA\xampp\htdocs\licentaCC\galerie\image_upload_script.php on line 45

Notice: Undefined index: uploaded_file in E:\LICENTA\xampp\htdocs\licentaCC\galerie\image_upload_script.php on line 46

 

 

 

Can anyone help me to solve this problem? Need to introduce isset, but i don;t know where begins and where end

Edited by Zane
Link to comment
Share on other sites

I don't have HTML for this code. 
 

<?php
if(isset($_SESSION['editname']) & !empty($_SESSION['editname'])){
 
$editname = $_SESSION['editname'];
$editdisplay = "galerie/uploads/codphp.php?name=r$editname&filter=";
if(empty($_POST['filter']))
$fid = 0;
else
$fid = $_POST['filter'];
$uploaded = "galerie/uploads/r$editname";
echo("<div align=center><img src=$uploaded> <img src=$editdisplay$fid></div><br />");
echo("<div align=center><form enctype=multipart/form-data method=post action=>");
echo("<input name=filter type=submit value=BW> ");
echo("<input name=filter type=submit value=Brightness> ");
echo("<input name=filter type=submit value=Colorize> ");
echo("<input name=filter type=submit value=Emboss> ");
echo("<input name=filter type=submit value=Blur> ");
echo("</form></div>");
 
 
}
else{
// Incarca un fisier pentru editare
require("galerie/image_upload_script.php");}
 
?>

 

 

The problem is that before I upload the image, i recive the notice. After I upload an image, notice dissappear. 

Link to comment
Share on other sites

The initial value is 0, because I haven't upload yet an image. After ai select the file(just select, not uplaod), all it's fine. 
I need to introduce

if(isset($_POST['uploaded_file'] & !empty($_POST['uploaded_file']) {...}else {...}

 

, but i can't understand all the code to know where to put this.

Link to comment
Share on other sites

I know this sounds crazy, but have you considered writing your own code rather than stealing broken scripts which you cannot understand from random websites and then asking others to fix them?

 

The code above is full of errors and potential vulnerabilities. That notice is your least problem. You'll probably need more time repairing that stuff (or making others repair it for you) than simply starting from scratch.

 

File uploads are inherently dangerous, so it's important that you do understand what you're doing and write solid code. But this isn't too difficult when you approach the problem systematically:

<?php

// TODO if the page is only accessible to registered users, check the session

// check if you've received a POST request
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
    // TODO check if all required fields are present

    // TODO check for upload errors: http://php.net/manual/en/features.file-upload.errors.php

    // TODO check the file extension; the pathinfo() function will be useful

    // TODO generate a purely random filename to avoid collisions, then store the file, preferrably *outside* of the document root

    // ...
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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