Jump to content

Recommended Posts

i got a class that is supposed to make a resize image and a thumb.

 

the class

<?php
class img{
var $fileTmp;
var $fileSize;
var $fileName;
var $db;
var $save;
var $name;

function img($tmp,$name,$save){
	$this->fileTmp = $tmp;
$this->fileSize = $size;
$this->fileName = $name;
$this->save = $save;
$this->db = new DB();
}

function reName(){
	$ext = strtolower(substr(basename($this->fileName),-4));
$rand = mt_rand(0, 32);
$newName = md5($rand . time());
$this->name = $newName.$ext;

return $this->name;

}

function reSize($w,$h){
	$srcImg=imagecreatefromjpeg($this->fileTmp);
$thumbImg=imagecreatetruecolor($w,$h);
imagecopyresized($thumbImg,$srcImg,0,0,0,0,$w,$h,imagesx($srcImg),imagesy($srcImg));
imagejpeg($thumbImg,$this->save.$this->name,100);
return $this->save.$this->name;
}

function thumb($w,$h){
	$srcImg=imagecreatefromjpeg($this->fileTmp);
$thumbImg=imagecreatetruecolor($w,$h);
imagecopyresized($thumbImg,$srcImg,0,0,0,0,$w,$h,imagesx($srcImg),imagesy($srcImg));
imagejpeg($thumbImg,$this->save.'tn_'.$this->name,100);
return $this->save.'tn_'.$this->name;
  }
  
function insert($id,$thumb,$path){
	$query = "INSERT INTO artist_photo(artist_id,thumb_path,image_path,date)VALUES('$id','$thumb','$path',NOW())";
$this->db->query($query);

}
}
?>

 

the call

if(isset($_POST['addimg'])){

$save = $_SERVER['DOCUMENT_ROOT'].'/music/image/';
$tmpPath = $_FILES['fileMusic']['tmp_name'];
$fileName= $_FILES['fileMusic']['name'];
$artist_id = $_POST['artist'];

$img = new img($tmpPath,$fileName,$save);

$img->reName();
$path = $img->reSize(230,310);
$thumb = $img->thumb(100,75);
$img->insert($artist_id,$thumb,$path);
}

 

i get these errors

Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\admin\lib\imgupload.php on line 31

 

Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\admin\lib\imgupload.php on line 31

 

Warning: imagecopyresized(): supplied argument is not a valid Image resource in C:\wamp\www\admin\lib\imgupload.php on line 31

 

Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\admin\lib\imgupload.php on line 39

 

Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\admin\lib\imgupload.php on line 39

 

Warning: imagecopyresized(): supplied argument is not a valid Image resource in C:\wamp\www\admin\lib\imgupload.php on line 39

Link to comment
https://forums.phpfreaks.com/topic/71921-class-image-upload-help/
Share on other sites

i narrow down the problem i seens that i am not getting anything from the tmp_name

<form action="" method="post" enctype="multipart/form-data" name="form1">
  <table width="100%" border="1">
    <tr>
      <td>artist</td>
      <td><label>
        <select name="artist" id="artist">
<?=$search->artistNames()?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td>image file</td>
      <td><label>
        <input type="file" name="fileimg" id="fileMusic">
      </label></td>
    </tr>
    <tr>
      <td><input name="addimg" type="hidden" id="addimg" value="true" /></td>
      <td><button type="submit" name="submit" id="submit">Upload</button></td>
    </tr>
  </table>
</form>

 

i don't understand why is not getting the tmp file.

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.