Some errors

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
Dimbata
New php-forum User
New php-forum User
Posts: 7
Joined: Fri Mar 29, 2013 7:45 am

Fri Mar 29, 2013 7:51 am

Hey, I am new to this forum and I'm not sure if I am posting in the right place but..
I have a php uploading system and when I upload something I get these errors:
Image
and here's my code:

Code: Select all

<?php   //line 25
require "config.php";
require "functions.php";

$error = '';
if (isset($_POST['submit']) && !empty($_FILES['pic']['name']) && !empty($_POST['subject']))
{
    if (in_array(strtolower(end(explode(".", $_FILES['pic']['name']))), $exp_pic))
    {
        if (in_array(strtolower(end(explode(".", $_FILES['pic']['name']))), $exp_file))
        {
            if ($_FILES['pic']['size'] > 0 && $_FILES['pic']['size'] <= ($max_size_pic * 1024))
            {
                if ($_FILES['pic']['size'] > 0 && $_FILES['pic']['size'] <= ($max_size_file * 1048576))
                {
                	$file_copy = preg_replace("/([\/])+/", "\\1", $file_copy."/");
                	$ex_pic = end(explode(".", $_FILES['pic']['name']));
                	$ex_file = end(explode(".", $_FILES['pic']['name']));
                	$new_name_pic = new_name($ex_pic);
                	$new_name_file = new_name($ex_file);
                	
                	while (file_exists($file_copy.$new_name_pic)) { $new_name_pic = new_name($ex_pic); }
                	while (file_exists($file_copy.$new_name_file)) { $new_name_file = new_name($ex_file); }
                	
					if (@copy($_FILES['pic']['tmp_name'], $file_copy.$new_name_file) && @copy($_FILES['pic']['tmp_name'], $file_copy.$new_name_pic))
					{
						mysql_query("INSERT INTO `files` (`pic`,`file`,`subject`) VALUES ('".$file_copy.$new_name_pic."','".$file_copy.$new_name_file."','".htmlspecialchars($_POST['subject'])."')");
						$error = "<br />Файла беше качен успешно! Върнете се обратно в <a href='index.php?page=gallery' style='text-decorations: none; color: #ececec;'>галерията</a>";
					}
					else
					{
						$error = "<br />Файла не беше качен!";
					}           	
                }
                else
                {
                    $error = "<br />Файла не трябва да превишава $max_size_file MB!";
                }
            }
            else
            {
                $error = "<br />Картинката не трябва да превишава $max_size_pic KB!";
            }
        }
        else
        {
            $error = "<br />Позволени са само следните разширения за файла: ".implode(",", $exp_file);
        }
    }
    else
    {
        $error = "<br />Позволени са само следните разширения за картинка: ".implode(",", $exp_pic);
    }
}
?>
<!--<b><u>Всички полета са задължителни!</u></b>-->
<form action="" enctype="multipart/form-data" method="post">
<table border="0" style="float: left;">
<tr><td>Изберете картинка:</td><td><input type="file" name="pic"></td></tr>
<tr><td>Име:</td><td><textarea name="subject" rows="1" cols="28"></textarea></td></tr>
</table>
<input type="submit" name="submit" value="Изпрати" style="margin: 3px 0 0 10px; width: 100px;">
</form>
functions.php

Code: Select all

<?php
function new_name($exp)
{
	$simbols = "1234567890qwertyuiopasdfgjklzxcvbnm";
	return substr(str_shuffle($simbols), 0, 25).".".$exp;
}

function sakra6tenie($var)
{
	global $max_simbols;
	if (strlen($var) > $max_simbols)
	{
		return nl2br(substr($var, 0, $max_simbols))."...";
	}
	else
	{
		return nl2br($var);
	}
}

function resize($pic)
{
	global $max_width_pic,$max_height_pic;
	list($width,$height) = getimagesize($pic);
    $ratio = $width / $height;
    
    if ($width > $max_width_pic || $height > $max_height_pic)
    {
        if ($width > $height)
        {
            $width = $max_width_pic;
            $height = $width / $ratio;
        }
        elseif ($width < $height)
        {
            $height = $max_height_pic;
            $width = $height * $ratio;
        }
        elseif ($width == $height)
        {
            $width = $max_width_pic;
            $height = $max_height_pic;
        }
    }
    $width = intval($width);
    $height = intval($height);
    return array("width" => $width, "height" => $height);
}
?>
config.php

Code: Select all

<?php
$db_conn = @mysql_connect("localhost", "root", "") or die(mysql_error()); // тук си пишете данните за връзка с MySQL
@mysql_select_db("upload", $db_conn) or die(mysql_error()); // тук ви е връзкта с базата данни.
mysql_query("SET NAMES cp1251");

$exp_pic = array("jpg","png","gif","jpeg","bmp"); // разширения за картинката
$exp_file = array("jpg","png","gif","jpeg","bmp"); // разширения за файловете
$max_size_pic = 5120; // запишете максималния размер на картинката(в KB)
$max_size_file = 15; // запишете максималния размер на файла(в MB)
$file_copy = "upload/"; // къде да се записват файловете

$max_simbols = 150; // колко символа да изкарва в индекса от описанието на всеки файл
$max_width_pic = 250; // максимална ширина на картинката
$max_height_pic = 250; // максимална височина на картинката
?>
Last edited by Dimbata on Fri Mar 29, 2013 8:49 am, edited 2 times in total.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Fri Mar 29, 2013 8:45 am

just copy and paste the errors please. am at work and don't need the ads from that site popping up in my history or cookies

Dimbata
New php-forum User
New php-forum User
Posts: 7
Joined: Fri Mar 29, 2013 7:45 am

Fri Mar 29, 2013 8:47 am

( ! ) Strict standards: Only variables should be passed by reference in C:\wamp\www\LoL Fan Site\uploading.php on line 32
Call Stack
# Time Memory Function Location
1 0.0008 144856 {main}( ) ..\index.php:0
2 0.0016 159632 include( 'C:\wamp\www\LoL Fan Site\uploading.php' ) ..\index.php:28


( ! ) Strict standards: Only variables should be passed by reference in C:\wamp\www\LoL Fan Site\uploading.php on line 34
Call Stack
# Time Memory Function Location
1 0.0008 144856 {main}( ) ..\index.php:0
2 0.0016 159632 include( 'C:\wamp\www\LoL Fan Site\uploading.php' ) ..\index.php:28


( ! ) Strict standards: Only variables should be passed by reference in C:\wamp\www\LoL Fan Site\uploading.php on line 41
Call Stack
# Time Memory Function Location
1 0.0008 144856 {main}( ) ..\index.php:0
2 0.0016 159632 include( 'C:\wamp\www\LoL Fan Site\uploading.php' ) ..\index.php:28


( ! ) Strict standards: Only variables should be passed by reference in C:\wamp\www\LoL Fan Site\uploading.php on line 42
Call Stack
# Time Memory Function Location
1 0.0008 144856 {main}( ) ..\index.php:0
2 0.0016 159632 include( 'C:\wamp\www\LoL Fan Site\uploading.php' ) ..\index.php:28

btw line 25 is "<?php" (starting line of the code)


Dimbata
New php-forum User
New php-forum User
Posts: 7
Joined: Fri Mar 29, 2013 7:45 am

Fri Mar 29, 2013 9:30 am

Ookey now I got another error..

Code: Select all

<?php
require "config.php";
require "functions.php";

$error = '';
if (isset($_POST['submit']) && !empty($_FILES['pic']['name']) && !empty($_POST['subject']))
{ $nm=(strtolower(end((explode(".", $_FILES['pic']['name'])))));
    if (in_array($nm ,$ex_pic))
    {
        if (in_array(strtolower(end($nm))))
        {
            if ($_FILES['pic']['size'] > 0 && $_FILES['pic']['size'] <= ($max_size_pic * 1024))
            {
                if ($_FILES['pic']['size'] > 0 && $_FILES['pic']['size'] <= ($max_size_file * 1048576))
                {
                	$file_copy = preg_replace("/([\/])+/", "\\1", $file_copy."/");
                	$ex_pic = end($nm);
                	$ex_file = end($nm);
                	$new_name_pic = new_name($ex_pic);
                	$new_name_file = new_name($ex_file);
                	
                	while (file_exists($file_copy.$new_name_pic)) { $new_name_pic = new_name($ex_pic); }
                	while (file_exists($file_copy.$new_name_file)) { $new_name_file = new_name($ex_file); }
                	
					if (@copy($_FILES['pic']['tmp_name'], $file_copy.$new_name_file) && @copy($_FILES['pic']['tmp_name'], $file_copy.$new_name_pic))
					{
						mysql_query("INSERT INTO `files` (`pic`,`file`,`subject`) VALUES ('".$file_copy.$new_name_pic."','".$file_copy.$new_name_file."','".htmlspecialchars($_POST['subject'])."')");
						$error = "<br />Файла беше качен успешно! Върнете се обратно в <a href='index.php?page=gallery' style='text-decorations: none; color: #ececec;'>галерията</a>";
					}
					else
					{
						$error = "<br />Файла не беше качен!";
					}           	
                }
                else
                {
                    $error = "<br />Файла не трябва да превишава $max_size_file MB!";
                }
            }
            else
            {
                $error = "<br />Картинката не трябва да превишава $max_size_pic KB!";
            }
        }
        else
        {
            $error = "<br />Позволени са само следните разширения за файла: ".implode(",", $exp_file);
        }
    }
    else
    {
        $error = "<br />Позволени са само следните разширения за картинка: ".implode(",", $exp_pic);
    }
}
?>
Error:

Code: Select all

( ! ) Notice: Undefined variable: ex_pic in C:\wamp\www\LoL Fan Site\uploading.php on line 32
Call Stack
#	Time	Memory	Function	Location
1	0.0010	144856	{main}( )	..\index.php:0
2	0.0017	158408	include( 'C:\wamp\www\LoL Fan Site\uploading.php' )	..\index.php:28


( ! ) SCREAM: Error suppression ignored for
( ! ) Warning: in_array() expects parameter 2 to be array, null given in C:\wamp\www\LoL Fan Site\uploading.php on line 32
Call Stack
#	Time	Memory	Function	Location
1	0.0010	144856	{main}( )	..\index.php:0
2	0.0017	158408	include( 'C:\wamp\www\LoL Fan Site\uploading.php' )	..\index.php:28
3	0.0116	173696	in_array ( )	..\uploading.php:32

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Fri Mar 29, 2013 10:12 am

you're only assigning ex_pic a value in some cases, but are not using isset() or !empty() to make sure it has a value before referencing it.

the second error is saying you are not using in_array() correctly because you're not passing it enough arguments. make sure to check php.net/function_name to verify usage if you're not sure.

jevin94
New php-forum User
New php-forum User
Posts: 8
Joined: Fri Mar 29, 2013 10:02 am
Contact:

Fri Mar 29, 2013 10:27 am

it will better to use include function in

require "config.php";
require "functions.php";

include("config.php");
include ("functions.php)";

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Majestic-12 [Bot] and 3 guests