php - Error in creating thumbnails from my form -


i've got problem script of mine create thumbnails images/photos users can upload form in personal website.

first of all, after possible controls prevent possible attacks, rename photo uploaded user using php functions, , i'd show logged user (and logging function use here sessions) uploaded images/photos thumbnails, giving him possibility click on them , obtain way photos original dimensions.

the problem got the thumbnails, i'm not able create!!!.

i created new table in mysql database way:

create table uploaded     (id_file int(11) unsigned not null auto_increment      url_file varchar(50) not null,      name_file varchar(100) not null,      type_file varchar(20) not null,      description varchar(255),      notes text,      data_insert datetime not null,      address_ip char(15) not null,      username varchar(20) not null,      id_user int(11) not null,      primary key(id_file)     ); 

then created file in php called vision.php show user images, , file parses file in query string way:

echo '<img src="thumb.php?id_file=' . $row['id_file'] . '" alt="' . $row['id_file'] . '" />  <br /><br /><br />';     

the directory contains photos called “uploaded” set permissions in 777. gave in fact in shell (i'm using gnu/linux distro) on local server apache this:

sudo chmod 777 uploaded

and see there photos myself uploded on localhost, test websites create.

anyway online got same problem.

here source of file called vision.php:

 <?php     try         {                // report php errors             error_reporting(-1);                         $pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception);              $stmt = $pdo->prepare("select * uploaded id_user = ? order id_file");             $stmt->execute(array($_session['id_user']));              if ( $row = $stmt->fetch(pdo::fetch_assoc) )                 {                        // here use do/while looop                                             {                             echo '<br /><br />your images:' . '&nbsp; &nbsp; <a href="upload.php">go back</a><br /><br />';                                                              echo '<img src="thumb.php?id_file=' . $row['id_file'] . '" alt="' . $row['id_file'] . '" />  <br /><br /><br />';                          }                      while ( $row = $stmt->fetch(pdo::fetch_assoc) );                                 }             else                 {                     echo '<br /><br /> <div class="centra">hi, ' . $_session['username'] . ', sent me no images now. <br /><br /> <a href="upload.php">send me image/photo, if wish</a></div>';                      include 'footer.php';                     exit;                 }          } // end try {}     catch (pdoexception $e)         {             echo "error!: " . $e->getmessage() . "<br />";             die;                 }    ?> 

and script called thumb.php:

<?php      // wanna have jpeg image thumbnail     header('content-type: image/jpeg');       // go on session     session_start();      require_once 'config_db.php';      try {         //chmod("./uploaded/", 0777);          // report php errors         error_reporting(-1);          $pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception);         $stmt = $pdo->prepare("select * uploaded id_file = ? order id_file");         // parameter contained in querystring in vision.php         $stmt->execute(array($_get['id_file']));         $row = stmt->fetch(pdo::fetch_assoc);                switch ($row['tipo_file']) {             case 'png':                              $image = imagecreatefrompng('uploaded/' . $row['nome_file'] . '.' . $row['tipo_file']);             break;                case 'jpg' || 'jpeg':              $image = imagecreatefromjpeg('uploaded/' . $row['nome_file'] . '.' . $row['tipo_file']);             break;              case 'gif':             $image = imagecreatefromgif('uploaded/' . $row['nome_file'] . '.' . $row['tipo_file']);             break;                default:                         die('impossible image extension');       }                         $width = imagesx($image);         $height = imagesy($image);          $thumbsize = 250;         $perc = min($thumbsize / $width, $thumbsize / $height);         $thumb_width = intval($perc * $width);         $thumb_height = intval($perc * $height);                         // thumbnail          $thumb = imagecreatetruecolor($thumb_width, $thumb_height);           imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);         imagejpeg($thumb, null, 80);                         // destroy thumbnail free memory server         imagedestroy($thumb);       } // end try {}     catch (pdoexception $e) {         echo "error!: " . $e->getmessage() . "<br />";         die;             }    ?>   

i'd add here errors can see error_file contained in directory /opt/lampp/logs:

i investigated error_file contained in directory /opt/lampp/logs , here found this:

[wed jun 26 19:37:34.279824 2013] [:error] [pid 2933] [client 127.0.0.1:43215] php warning:  **imagecreatefromjpeg(uploaded/046ccd6f930959786f71447f2ecf228d814481eb40481889d9ea619191a153cb12f585bbae867a66.jpeg): failed open stream: no such file or directory in /opt/lampp/htdocs/new_site_local/thumb.php on line 35, referer:[http://localhost/new_site_local/vision.php]** [wed jun 26 19:37:34.279915 2013] [:error] [pid 2933] [client 127.0.0.1:43215] php warning:  imagesx() expects parameter 1 resource, boolean given in /opt/lampp/htdocs/new_site_local/thumb.php on line 47, referer:[    http://localhost/new_site_local/vision.php] [wed jun 26 19:37:34.279938 2013] [:error] [pid 2933] [client 127.0.0.1:43215] php warning:  imagesy() expects parameter 1 resource, boolean given in /opt/lampp/htdocs/new_site_local/thumb.php on line 48, referer: [http://localhost/new_site_local/vision.php] [wed jun 26 19:37:34.279961 2013] [:error] [pid 2933] [client 127.0.0.1:43215] php warning:  division 0 in /opt/lampp/htdocs/new_site_local/thumb.php on line 59, referer:[http://localhost/new_site_local/vision.php] 

etc.

thanks all!

the first error the important

"failed open stream: no such file or directory" means code couldn't find file. possibly because file's relative path not expanded expected to.

try using var_dump(realpath($filename)) this:

case 'jpg' || 'jpeg':      $filename = 'uploaded/' . $row['nome_file'] . '.' . $row['tipo_file'];     var_dump(          file_exists($filename),          realpath($filename),          is_readable($filename)     );     $image = imagecreatefromjpeg($filename);     break; 

you'll notice file_exists, realpath, is_readable yield boolean(false).

for testing , error reporting , displaying

try separating actual thumbnail generation code database read code. hard code file name , see if thumbnail generation works file name.

also try using error_reporting(e_all); , ini_set('display_errors', true); able read errors php might sending.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -