ChrisScicluna Posted August 7, 2007 Share Posted August 7, 2007 Hi all users, I am new to this forum but iv been developing with php for these last 6 months. I have a cms (content managment system) which allows me to upload pictures, now the problem is that locally it is working (i have apache installed) but when i upload it to the server it is not working from the php that adds the picture along with details i am calling a config.php from a library file which has the path where the thumbnails and images should be stored. But it seems that it is not storing them at all neither in the directory i specified in the config.php and neither anywhere on the server. I checked the rights to the files and the rights ok i have permission to write in them. I think the problem is with the path i did an absolute url and it still did not work. Can anyone help me? I would be really gratefull! Many Thanks and Kind Regards, Chris Scicluna P.s. Please help me... Quote Link to comment https://forums.phpfreaks.com/topic/63791-uploading-images-with-php-difficulty/ Share on other sites More sharing options...
spdwrench Posted August 7, 2007 Share Posted August 7, 2007 I was having some serious issues with large image files not uploading... believe it or not after pulling out my hair for a week or so... I looked at my phpinfo.php file and found the max upload set to 2M I changed it and all is good... I dunno if this is your issue? it does not return an error when this happens. Paul Quote Link to comment https://forums.phpfreaks.com/topic/63791-uploading-images-with-php-difficulty/#findComment-317921 Share on other sites More sharing options...
ChrisScicluna Posted August 7, 2007 Author Share Posted August 7, 2007 Hi Paul thanks for your answer. No basically it is smaller than 2mb so i dont think that is the issue, here is the php of the file that is uploading the image: <?php require_once 'PATH WHERE CONFIG FILE IS LOCATED'; require_once 'PATH WHERE FUNCTIONS FILE IS LOCATED'; if(isset($_POST['txtName'])) { $codeNumber = $_POST['txtName']; $priceNumber = $_POST['priceLm']; $priceEuroNumber = $_POST['priceEuro']; $colourNumber = $_POST['colourRGB']; $sizeNumber = $_POST['sizeCM']; $imgName = $_FILES['fleImage']['name']; $tmpName = $_FILES['fleImage']['tmp_name']; // we need to rename the image name just to avoid // duplicate file names // first get the file extension $ext = strrchr($imgName, "."); // then create a new random name $newName = md5(rand() * time()) . $ext; // the album image will be saved here $imgPath = ALBUM_IMG_DIR . $newName; // resize all album image $result = createThumbnail($tmpName, $imgPath, THUMBNAIL_WIDTH); if (!$result) { echo "Error uploading file"; exit; } if (!get_magic_quotes_gpc()) { $codeNumber = addslashes($codeNumber); $priceNumber = addslashes($priceNumber); $priceEuroNumber = addslashes($priceEuroNumber); $colourNumber = addslashes($colourNumber); $sizeNumber = addslashes($sizeNumber); } $query = "INSERT INTO tbl_album (al_code, al_lm, al_euro, al_colour, al_size, al_image, al_date) VALUES ('$codeNumber', '$priceNumber', '$priceEuroNumber','$colourNumber','$sizeNumber','$newName', NOW())"; mysql_query($query) or die('Error, add album failed : ' . mysql_error()); // the album is saved, go to the album list echo "<script>window.location.href='index.php?page=list-album';</script>"; exit; } ?> <form action="" method="post" enctype="multipart/form-data" name="frmAlbum" id="frmAlbum"> <table width="100%" border="0" cellpadding="2" cellspacing="1" class="table_grey"> <tr> <th width="150"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Code Number:</font></th> <td width="80" bgcolor="#FFFFFF"> <input name="txtName" type="text" id="txtName"></td> </tr> <tr> <th height="46"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Price in Lm:</font></th> <td bgcolor="#FFFFFF"><input name="priceLm" type="text" id="priceLm"></td> </tr> <tr> <th height="46"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Price in Euro:</font></th> <td bgcolor="#FFFFFF"><input name="priceEuro" type="text" id="priceEuro"></td> </tr> <tr> <th height="46"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Colour:</font></th> <td bgcolor="#FFFFFF"><input name="colourRGB" type="text" id="colourRGB"></td> </tr> <tr> <th width="150" height="46"><p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Sizes:</font></p></th> <td bgcolor="#FFFFFF"><input name="sizeCM" type="text" id="sizeCM"></td> </tr> <tr> <th width="150"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Image:</font></th> <td bgcolor="#FFFFFF"> <input name="fleImage" type="file" class="box" id="fleImage"></td> </tr> <tr> <td width="150" bgcolor="#FFFFFF"> </td> <td bgcolor="#FFFFFF"> <input name="btnAdd" type="submit" id="btnAdd" value="Add"> <input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.history.back();"></td> </tr> </table> </form> ___________________________________________________________________________________________________ and this is the path in the php config file: // an album can have an image used as thumbnail // we save the album image here define('ALBUM_IMG_DIR', 'http://www.sml.com.mt/webroot/gallery/images/Album/'); // all images inside an album are stored here define('GALLERY_IMG_DIR', 'http://www.sml.com.mt/webroot/gallery/images/gallery/'); __________________________________________________________________________________________________ if you go to http://www.sml.com.mt/try/admin/index.php you can see that the php gets the info from the database but the picture is not there Thanks again for your reply, hope you can help me out Quote Link to comment https://forums.phpfreaks.com/topic/63791-uploading-images-with-php-difficulty/#findComment-317946 Share on other sites More sharing options...
ChrisScicluna Posted August 7, 2007 Author Share Posted August 7, 2007 Sorry i forgot the login Username: neilsmledit Password: smledit2007! Thanks & Kind Regards Quote Link to comment https://forums.phpfreaks.com/topic/63791-uploading-images-with-php-difficulty/#findComment-317948 Share on other sites More sharing options...
teng84 Posted August 7, 2007 Share Posted August 7, 2007 can you point the line that uploads the image Quote Link to comment https://forums.phpfreaks.com/topic/63791-uploading-images-with-php-difficulty/#findComment-317952 Share on other sites More sharing options...
ChrisScicluna Posted August 7, 2007 Author Share Posted August 7, 2007 $imgName = $_FILES['fleImage']['name']; $tmpName = $_FILES['fleImage']['tmp_name']; // we need to rename the image name just to avoid // duplicate file names // first get the file extension $ext = strrchr($imgName, "."); // then create a new random name $newName = md5(rand() * time()) . $ext; // the album image will be saved here $imgPath = ALBUM_IMG_DIR . $newName; // resize all album image $result = createThumbnail($tmpName, $imgPath, THUMBNAIL_WIDTH); This is the part that has to do with the image, and it saves the randomname into the mysql database so that when information is needed the name is picked up from mysql and the image with the respective random name is loaded next to the details Quote Link to comment https://forums.phpfreaks.com/topic/63791-uploading-images-with-php-difficulty/#findComment-317954 Share on other sites More sharing options...
ChrisScicluna Posted August 7, 2007 Author Share Posted August 7, 2007 If this can help you in the functions.php file i have this: <?php /* Upload an image and create the thumbnail. The thumbnail is stored under the thumbnail sub-directory of $uploadDir. Return the uploaded image name and the thumbnail also. */ function uploadImage($inputName, $uploadDir) { $image = $_FILES[$inputName]; $imagePath = ''; $thumbnailPath = ''; // if a file is given if (trim($image['tmp_name']) != '') { $ext = substr(strrchr($image['name'], "."), 1); // generate a random new file name to avoid name conflict // then save the image under the new file name $imagePath = md5(rand() * time()) . ".$ext"; $result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath); if ($result) { // create thumbnail $thumbnailPath = md5(rand() * time()) . ".$ext"; $result = createThumbnail($uploadDir . $imagePath, $uploadDir . 'thumbnail/' . $thumbnailPath, THUMBNAIL_WIDTH); // create thumbnail failed, delete the image if (!$result) { unlink($uploadDir . $imagePath); $imagePath = $thumbnailPath = ''; } else { $thumbnailPath = $result; } } else { // the image cannot be uploaded $imagePath = $thumbnailPath = ''; } } return array('image' => $imagePath, 'thumbnail' => $thumbnailPath); } /* Create a thumbnail of $srcFile and save it to $destFile. The thumbnail will be $width pixels. */ function createThumbnail($srcFile, $destFile, $width, $quality = 75) { $thumbnail = ''; if (file_exists($srcFile) && isset($destFile)) { $size = getimagesize($srcFile); $w = number_format($width, 0, ',', ''); $h = number_format(($size[1] / $size[0]) * $width, 0, ',', ''); $thumbnail = copyImage($srcFile, $destFile, $w, $h, $quality); } // return the thumbnail file name on sucess or blank on fail return basename($thumbnail); } /* Copy an image to a destination file. The destination image size will be $w X $h pixels */ function copyImage($srcFile, $destFile, $w, $h, $quality = 75) { $tmpSrc = pathinfo(strtolower($srcFile)); $tmpDest = pathinfo(strtolower($destFile)); $size = getimagesize($srcFile); if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg") { $destFile = substr_replace($destFile, 'jpg', -3); $dest = imagecreatetruecolor($w, $h); //imageantialias($dest, TRUE); } elseif ($tmpDest['extension'] == "png") { $dest = imagecreatetruecolor($w, $h); //imageantialias($dest, TRUE); } else { return false; } switch($size[2]) { case 1: //GIF $src = imagecreatefromgif($srcFile); break; case 2: //JPEG $src = imagecreatefromjpeg($srcFile); break; case 3: //PNG $src = imagecreatefrompng($srcFile); break; default: return false; break; } imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]); switch($size[2]) { case 1: case 2: imagejpeg($dest,$destFile, $quality); break; case 3: imagepng($dest,$destFile); } return $destFile; } Quote Link to comment https://forums.phpfreaks.com/topic/63791-uploading-images-with-php-difficulty/#findComment-317959 Share on other sites More sharing options...
teng84 Posted August 7, 2007 Share Posted August 7, 2007 did you print the variable to see if the path is correct Quote Link to comment https://forums.phpfreaks.com/topic/63791-uploading-images-with-php-difficulty/#findComment-317962 Share on other sites More sharing options...
ChrisScicluna Posted August 8, 2007 Author Share Posted August 8, 2007 What do you mean by printing the variable? Can you please tell me exactly what i have to do thanks I would be very gratefull if you helped me in solving this problem since this is the only thing that is keeping me away from finishing the site. Thanks & Kind Regards, Chris Scicluna Quote Link to comment https://forums.phpfreaks.com/topic/63791-uploading-images-with-php-difficulty/#findComment-318220 Share on other sites More sharing options...
chronister Posted August 8, 2007 Share Posted August 8, 2007 Is the directory in which your trying to store the files writable?? Unless someone else knows something I don't, I had to set the dir for my image upload script to 777 Nate Quote Link to comment https://forums.phpfreaks.com/topic/63791-uploading-images-with-php-difficulty/#findComment-318227 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.