Files stopped uploading

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aghast
Forum Newbie
Posts: 16
Joined: Wed Jul 28, 2010 3:22 pm

Files stopped uploading

Post by aghast »

Hello everyone. I have an image uploader using fancy upload that worked great on the testing server but once I put it on the web server it stopped working. The uploader works but it uploads nothing. Here is the code.

Code: Select all

//save post images    
        if (isset($_POST['images']))
        {
            $count = count($_POST['images']);
        }
        else
        {
            $count = 0;
        }        
        for ($i=0; $i<$count; $i++)
        {
            $image_name = $_POST['images'][$i];
            $ext = get_ext($image_name );
            $uniq = str_replace('.'.$ext, '', $image_name);
            $size = filesize(IMG_DIR . $image_name);
            //create a thumbnail
            $im = imagecreatefromstring(file_get_contents(IMG_DIR . $image_name));
            $height = imagesy($im);
            $width = imagesx($im);
            $im2 = imagecreatetruecolor(THUMB_WID, THUMB_HEI);
            imagecopyresampled($im2, $im, 0, 0, 0, 0, THUMB_WID, THUMB_HEI, $width, $height);
            $thumb_name = "sm_" . $uniq . '.jpg';
            imagejpeg($im2, IMG_DIR . $thumb_name);
            //save in DB
            $sql = sprintf("INSERT INTO archive_image(archive_id, file, thumb, size, width, height)
                            VALUES('%s','%s','%s','%s','%s','%s')",
                            $id, $image_name, $thumb_name, $size, $width, $height);
            mysql_query($sql);
        }
thanks in advance for any suggestions
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Files stopped uploading

Post by VladSun »

I think you've shown us the part of the code for processing an already uploaded image. You need to show the part where
$_FILE and move_uploaded_file() appear.
There are 10 types of people in this world, those who understand binary and those who don't
aghast
Forum Newbie
Posts: 16
Joined: Wed Jul 28, 2010 3:22 pm

Re: Files stopped uploading

Post by aghast »

VladSun wrote:I think you've shown us the part of the code for processing an already uploaded image. You need to show the part where
$_FILE and move_uploaded_file() appear.
Multitasking is no ones friend..

Code: Select all

<?php
// Validation
define('IMG_DIR', '../images/');
define('MAX_SIZE', 2000);
include '/../../includes/functions.php';


//$f = fopen('test.txt', 'w+');

$error = false;

//is uploaded?
if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) 
{
    $error = 'Invalid Upload';
}

//is image?
$ext = get_ext($_FILES['Filedata']['name']);
$allowed = array('jpg', 'jpeg', 'jpe', 'png', 'gif'); 
if (!in_array($ext, $allowed))
{
    $error = 'Invalid image extension';
} 

//compare the size with the maximum size we defined and print error if bigger
$size = filesize($_FILES['Filedata']['tmp_name']);                
if ($size > MAX_SIZE*1024)
{
    $error = 'You have exceeded the size limit';
}

// Processing

//the new name will be containing the full path where it will be stored (images folder)
$uniq = uniqid();
$image_name = $uniq . '.' . $ext;
//we verify if the image has been uploaded, and print error if not
if (!copy($_FILES['Filedata']['tmp_name'], IMG_DIR . $image_name))
{
    $error = 'Upload unsuccessfull';            
}
$return['src'] = $image_name;   

//fwrite($f, 'TRZY');

if ($error) 
{
    $return['status'] = '0';
    $return['error'] = $error;

}
else 
{
    $return['status']    = '1';
    $return['name']        = $_FILES['Filedata']['name'];

    // Our processing, we get a hash value from the file
    $return['hash']     = md5_file($_FILES['Filedata']['tmp_name']);

    // ... and if available, we get image data
    $info = @getimagesize($_FILES['Filedata']['tmp_name']);

    if ($info) 
    {
        $return['width']    = $info[0];
        $return['height']    = $info[1];
        $return['mime']        = $info['mime'];
    }

}


// Output

if (isset($_REQUEST['response']) && $_REQUEST['response'] == 'xml') 
{
    //header('Content-type: text/xml');

    // Really dirty, use DOM and CDATA section!
    echo '<response>';
    foreach ($return as $key => $value) 
    {
        echo "<$key><![CDATA[$value]]><$key>";
    }
    echo '</response>';
}
else 
{
    //header('Content-type: application/json');

    echo json_encode($return);
}
aghast
Forum Newbie
Posts: 16
Joined: Wed Jul 28, 2010 3:22 pm

Re: Files stopped uploading

Post by aghast »

ok, nevermind. I disabled the datepicker and it works apparently the calendar and the uploader don't like each other. Which means it has nothing to do with the php. Sorry to waist precious forum time and thanks.
Post Reply