troubleshooting Question

Image uploaded but unable to view

Avatar of Derokorian
DerokorianFlag for United States of America asked on
PHPHTMLApache Web Server
11 Comments2 Solutions250 ViewsLast Modified:
I have an image upload script which seems to be working fine:

		// Process new images. Resize to thumbnail and gallery.
		$path = $picpath . $_POST['gallery'] . '/';
		if( !is_dir($path) ) mkdir($path);
		for( $i=1; $i<=$upload_at_once; $i++ ) {
			if( empty($_POST['title'.$i]) ) continue;
			if( $_FILES['photo'.$i]['error'] > 0 ) trigger_error('#'. __LINE__ .'/'. $i .' - There was an error processing your file.',E_USER_ERROR);
			if( !$_FILES['photo'.$i]['size'] > 0 ) trigger_error('#'. __LINE__ .'/'. $i .' - There was an error processing your file.',E_USER_ERROR);
			list($name,$ext) = explode('.',$_FILES['photo'.$i]['name']);
			$name = substr($name,0,25);
			$name = $name . microtime(TRUE);
			$name = preg_replace('/[^a-zA-Z0-9_-]/','',$name);
			$galfull = $path . $name . '.' . $ext;
			$thfull = $path . $name . '_th.' . $ext;
			$temp = $path . 'temporary.' . $ext;
			if( !move_uploaded_file($_FILES['photo'.$i]['tmp_name'],$temp) ) trigger_error('#'. __LINE__ .'/'. $i .' - There was an error processing your file.',E_USER_ERROR);
			if( !imageResize($temp,$thfull,$thw,$thh,TRUE) ) trigger_error('#'. __LINE__ .'/'. $i .' - There was an error processing your file into a thumbnail.',E_USER_ERROR);
			if( !imageResize($temp,$galfull,$galw,$galh,TRUE) ) trigger_error('#'. __LINE__ .'/'. $i .' - There was an error processing your file into gallery size.',E_USER_ERROR);
			$sql = sprintf("INSERT INTO home_images
			if( !$db->query($sql) ) trigger_error('#'. __LINE__ .'/'. $i .' - There was an error adding to the database.',E_USER_ERROR);
		$content .= 'Successfully added new images.';

Open in new window

This is included by my loading mechanism and the content placed where it goes within the template. I then have an image viewing script, which is working for most pictures:

$image = ISSET($_GET['image']) ? $_GET['image'] : FALSE;
if( !$image ) die('Error #501:<br />There was a problem loading the image.'. var_dump($_GET));

 * Print the page

$sql = 'SELECT * FROM home_images WHERE id_image='. $image;
$result = $db->query($sql);
if( !$result ) die('MySQL Error: ('. mysqli_errno() .') '. mysqli_error .'<br />Query: '. $sql);
if( !$result->num_rows > 0 ) die('Error loading the selected image, please try again later.');
$info = $result->fetch_assoc();

$content .= '
<div id="main">
    <div style="height:5px;">&nbsp;</div>
    <center><a href="javascript:void()" onclick="history.go(-1);return false;">Back to previous page</a></center>
    <img src="'. sprintf('%sresources/%s%s.%s',$siteurl,$info['image_path'],$info['image_file'],$info['image_ext']) .'" style="padding: 10px 10px;" />
    <br />
    <h4>'. $info['image_title'] .'</h4>
    <p>'. $info['image_caption'] .'</p>
if( !empty($info['image_photographer']) ) $content .= '<p class="note">Photos provided by '. $info['image_photographer'] .'</p>';
$content .= '</div>
$sql = 'UPDATE home_images SET image_views = image_views+1 WHERE id_image='. $image;

Open in new window

However I just used this script to upload 5 new pictures and they are not showing either in thumbnail or the view file. Also when I try to access these files directly via the full url i get a 404 not found error. When I log into my FTP program I verified that these images are exactly where they are supposed to be.

Any idea why I can't seem to access these newly uploaded images? As I said its working fine for images that have been for there for a while, however the new images I just uploaded aren't showing, even tho they are located where the src tag says they are, as verified by the file system.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 2 Answers and 11 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 2 Answers and 11 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004