0

I have this code below, to create a folder year and month inside uploads folder, if this folders dont exist.

And Then I call my function uploadImage to do the upload inside the month folder:

My code for this:

if(!empty($_FILES['thumb']['tmp_name']))
{
    $folder     = '../uploads/';
    $year   = date('Y');
    $month  = date('m');

    if(!file_exists($folder.$year)){
    mkdir($folder.$year,0755);
    }
    if(!file_exists($folder.$year.'/'.$month)){
    mkdir($folder.$year.'/'.$month,0755);
    }
    $img = $_FILES['thumb']; //get thumb of the form 
    $ext = substr($img['name'],-3);
    $f['thumb'] = $year.'/'.$month.'/'.$f['url'].'.'.$ext;
    uploadImage($img['tmp_name'], $f['url'].'.'.$ext, '800', $folder);

}

My uploader function:

function uploadImage($tmp, $name, $width, $folder){
$ext = substr($name,-3);

switch($ext){
    case 'jpg': $img = imagecreatefromjpeg($tmp); break;
    case 'png': $img = imagecreatefrompng($tmp); break;
    case 'gif': $img = imagecreatefromgif($tmp); break; 
}       
$x = imagesx($img);
$y = imagesy($img);
$height = ($width*$y) / $x;
$newImage   = imagecreatetruecolor($width, $height);

imagealphablending($newImage,false);
imagesavealpha($newImage,true);
imagecopyresampled($newImage, $img, 0, 0, 0, 0, $width, $height, $x, $y);

switch($ext){
    case 'jpg': imagejpeg($newImage, $folder.$name, 100); break;
    case 'png': imagepng($newImage, $folder.$name); break;
    case 'gif': imagegif($newImage, $folder.$name); break;  
}
imagedestroy($img);
imagedestroy($newImage);
}

For me everything seems good, and I dont have erros but the upload is not working!

John23
  • 219
  • 2
  • 9
  • 31
  • 1
    possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – John Conde Apr 05 '14 at 15:23

1 Answers1

1

Looks like your passing your base folder to the upload, should be something like:

'800', $folder.$year.'/'.$month);

Also your $name seems to be a URL of some sort, it needs to be a valid file name.

WhoIsRich
  • 4,053
  • 1
  • 33
  • 19
  • Thank you for your answer, but didnt solve the problem! – John23 Apr 06 '14 at 19:12
  • All I can suggest is that you add print_r($variableName); at various places in your uploadImage function to check that the paths, file name, and folder are being passed correctly. – WhoIsRich Apr 07 '14 at 22:41