have some code which uploads a pic to folder on server is it poss if its jpg it can change it to JPG here is the upload code i use cheers Doug <?php //set where you want to store files //in this example we keep file in folder upload //$HTTP_POST_FILES['ufile']['name']; = upload file name //for example upload file name cartoon.gif . $path will be upload/cartoon.gif $path= "pics/".$HTTP_POST_FILES['ufile']['name']; if($ufile !=none) { if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { echo "Successful<BR/>"; //$HTTP_POST_FILES['ufile']['name'] = file name //$HTTP_POST_FILES['ufile']['size'] = file size //$HTTP_POST_FILES['ufile']['type'] = type of file echo "File Name :".$HTTP_POST_FILES['ufile']['name']."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; echo "<img src=\"$path\" width=\"150\" height=\"150\">"; } else { echo "Error"; } } ?>
Before the line $path= "pics/".$HTTP_POST_FILES['ufile']['name']; PHP: Try adding the code: if (preg_match(/"\.JPG$/", $HTTP_POST_FILES['ufile']['name'])) { $HTTP_POST_FILES['ufile']['name'] = preg_replace("/\.JPG$/", ".jpg", $HTTP_POST_FILES['ufile']['name']); } PHP: This basically says that if $HTTP_POST_FILES['ufile']['name'] ends with .JPG then change that .JPG to .jpg
thanks just put code in and tells me syntex error in this line if (preg_match(/"\.JPG$/", $HTTP_POST_FILES['ufile']['name'])) {
Sorry, the correct segment would be if (preg_match("/\.JPG$/", $HTTP_POST_FILES['ufile']['name'])) { $HTTP_POST_FILES['ufile']['name'] = preg_replace("/\.JPG$/", ".jpg", $HTTP_POST_FILES['ufile']['name']); } PHP: I had the / outside of the quotation marks
Here are some code that I use often you can try and or modify it.. // checking which type of image is $imgType = exif_imagetype($_FILES['upload_image']['tmp_name']); // catching extention from file name // here you can change ext as you want if($imgType === 1){ $ext = ".gif"; } if($imgType === 2){ $ext = ".jpg"; } if($imgType === 3){ $ext = ".png"; } $uplDir = "picture/"; // where you want to your image $picName = "picture_name"; $tarPath = $uplDir.$picName.$ext; // lets save pic into picture folder move_uploaded_file($_FILES['uploadIn']['tmp_name'], $tarPath); image type list http://php.net/manual/en/function.exif-imagetype.php tell me if you have any other problem
ok all works fine big thanks can i add a line some where if the file exsits asks if overwrite at moment just gives error cheers Doug
To check a file is there all you need to do is use this function is_file('path to file here') that will return boolean (true/false) if it's true rename the file. Glen
hey dougvcd, you can use file_exists($tarPath); before move_uploaded_file($_FILES['uploadIn']['tmp_name'], $tarPath); cheers webshore88